Saturday, May 15, 2010

Asp.net MultiView

A multiview is useful when data from one page need to be transferred to another page. Example to jump from one page to other in a shopping cart web site. For each page step of shopping each views in MultiView can be used. MultiView control shows only one view at a time. So the same page seems to more than one page depending upon number of views present inside a multiview.

To use a MultiView control just drag and drop a MultiView control from the toolbox. Then add views from the toolbox in the blank area the MultiView control. Add more views by drag and dropping the view control on the grey header of previously added view control.

E.g.:

WebForm1.aspx

<asp:Button ID="Button1" runat="server" Text="General"
            onclick="Button1_Click" />

<asp:MultiView ID="MultiView1" runat="server">
       <asp:View ID="View2" runat="server">
           View Two
       </asp:View>
       <asp:View ID="View1" runat="server">
           View One
       </asp:View>
   </asp:MultiView>

To view the contents inside a view say View1 when Button1 is clicked use the following code.

protected void Button1_Click(object sender, EventArgs e)
{
    MultiView1.SetActiveView(View1);
}

No comments:

Post a Comment