Skip to main content

How to use MultiView control in asp.net

MultiView and View Server Control
MultiView is an asp.net web server control. The View control is also an asp.net web server control. But view control always is contained within multiview control. Both multiview and view control act as a container for other controls and markup. Only one view can be defined as an active view in MultiView. MultiView ActiveViewIndex property specifies the active view within view collections of a multiview. Only active view control is rendered to the page.

We can navigate views by setting the multiview ActiveViewIndex property value. ActiveViewIndex property holds the specified view's index number. MultiView control can include navigation buttons that we can add to each view.

We can create a navigation button by adding any Button, LinkButton, or ImageButton server control to each view. For that, we need to set the CommandName and CommandArgument properties of each view. Reserved CommandName values are NextView, PrevView, SwitchViewByID, and SwitchViewByIndex. NextView and PrevView corresponding CommandArgument have no values. SwitchViewByID CommandArgument value is the ID of the view to switch to. SwitchViewByIndex CommandArgument value is the index number of the view to switch to.

You can create a multi-page form using MultiView and view controls. But Wizard control is better for creating a multiple-page form that needs to fill step by step. MultiView and view control provide support similar to Wizard control. The Wizard has more built-in UI elements than multiview control. So MultiView is a better choice if we want to display a view based on condition rather than sequence.

The following example source code demonstrates to us how can we use MultiView and view controls in asp.net. In this web form, we create a multiview control and five view controls within it. Each view displays a beautiful image using Image server control. We also put a button control on each view to navigate views. When the user clicks the navigation button, the MultiView control displays the next view.
MultiView.aspx

<%@ Page Language="C#" %><!DOCTYPE html><script runat="server">    protected void Page_Load(object sender, System.EventArgs e) {        if(!Page.IsPostBack){            MultiView1.ActiveViewIndex = 0;           }    }    void NextImage(object sender, System.EventArgs e)    {        MultiView1.ActiveViewIndex += 1;    }    protected void Page_PreRender(object sender, System.EventArgs e) {        Label1.Text = "Beautiful birds images : " +            (MultiView1.ActiveViewIndex + 1).ToString() +            " of " + MultiView1.Views.Count.ToString();    }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>How to use MultiView control in asp.net</title></head><body style="padding:25px">    <form id="form1" runat="server">    <div>        <h2 style="color:MidnightBlue; font-style:italic;">                  How to use MultiView        </h2>              <hr width="450" align="left" color="Gainsboro" />        <asp:Label            ID="Label1"            runat="server"            Font-Bold="true"            Font-Names="Comic Sans MS"            ForeColor="Crimson"            Font-Italic="true"            Font-Size="X-Large"            />        <br /><br />        <asp:MultiView ID="MultiView1" runat="server">            <asp:View ID="View1" runat="server">                <asp:Image                     ID="Image1"                     runat="server"                     ImageUrl="~/Images/birds1.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button1"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View2" runat="server">                <asp:Image                     ID="Image2"                     runat="server"                     ImageUrl="~/Images/birds2.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button2"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View3" runat="server">                <asp:Image                     ID="Image3"                     runat="server"                     ImageUrl="~/Images/birds3.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button3"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View4" runat="server">                <asp:Image                     ID="Image4"                     runat="server"                     ImageUrl="~/Images/birds4.jpg"                    Height="300"                    />                <br />                <asp:Button                     ID="Button4"                     runat="server"                     Text="Next Image"                     OnClick="NextImage"                    Font-Bold="true"                    ForeColor="Navy"                    Height="45"                    Width="150"                    />            </asp:View>            <asp:View ID="View5" runat="server">                <asp:Image                     ID="Image5"                     runat="server"                     ImageUrl="~/Images/birds5.jpg"                    Height="300"                    />            </asp:View>        </asp:MultiView>    </div>    </form></body></html>

Popular posts from this blog

Restricting Jetpack Compose TextField to Numeric Input Only

Jetpack Compose has revolutionized Android development with its declarative approach, enabling developers to build modern, responsive UIs more efficiently. Among the many components provided by Compose, TextField is a critical building block for user input. However, ensuring that a TextField accepts only numeric input can pose challenges, especially when considering edge cases like empty fields, invalid characters, or localization nuances. In this blog post, we'll explore how to restrict a Jetpack Compose TextField to numeric input only, discussing both basic and advanced implementations. Why Restricting Input Matters Restricting user input to numeric values is a common requirement in apps dealing with forms, payment entries, age verifications, or any data where only numbers are valid. Properly validating input at the UI level enhances user experience, reduces backend validation overhead, and minimizes errors during data processing. Compose provides the flexibility to implement ...

jetpack compose - TextField remove underline

Compose TextField Remove Underline The TextField is the text input widget of android jetpack compose library. TextField is an equivalent widget of the android view system’s EditText widget. TextField is used to enter and modify text. The following jetpack compose tutorial will demonstrate to us how we can remove (actually hide) the underline from a TextField widget in an android application. We have to apply a simple trick to remove (hide) the underline from the TextField. The TextField constructor’s ‘colors’ argument allows us to set or change colors for TextField’s various components such as text color, cursor color, label color, error color, background color, focused and unfocused indicator color, etc. Jetpack developers can pass a TextFieldDefaults.textFieldColors() function with arguments value for the TextField ‘colors’ argument. There are many arguments for this ‘TextFieldDefaults.textFieldColors()’function such as textColor, disabledTextColor, backgroundColor, cursorC...

jetpack compose - Image clickable

Compose Image Clickable The Image widget allows android developers to display an image object to the app user interface using the jetpack compose library. Android app developers can show image objects to the Image widget from various sources such as painter resources, vector resources, bitmap, etc. Image is a very essential component of the jetpack compose library. Android app developers can change many properties of an Image widget by its modifiers such as size, shape, etc. We also can specify the Image object scaling algorithm, content description, etc. But how can we set a click event to an Image widget in a jetpack compose application? There is no built-in property/parameter/argument to set up an onClick event directly to the Image widget. This android application development tutorial will demonstrate to us how we can add a click event to the Image widget and make it clickable. Click event of a widget allow app users to execute a task such as showing a toast message by cli...