- View and Multiview Web Server Control
in ASP.NET environment,The MultiView control can servers as a multiple wizards. MultiView represents a control that acts as a container for groups of View controls. It allows you to define a group of View controls, where each View control contains child controls.
for example, in a matrimonial application, you application can be redering a multiple view control to the user based on the criteria such as user contact details,user personal details, user family detaisl, etc.
- To add a View and Multiview control to a page
- Type an <asp:MultiView> element in the page.
- Type an <asp:View> element within the Multiview Web Control.
- Includes any other control or static text into the View Control.
- likewise above 2 steps,includes more view controls in the MultiView Control
- Set the MultiView control's ActiveViewIndex property to the index value of the View control to display. If you do not want to display any View controls, set the property to -1.
- Add code to programmatically set the ActiveViewIndex property to set which View control is displayed.
the following code snippets demonstrates a View and Multiview control
-
in .aspx.cs page,
-
public enum strFindType { NotSet = -1, Products = 0, Category = 1 }
protected void Button1_Click(Object sender, System.EventArgs e) { if(MultiView1.ActiveViewIndex > -1) { String strTerm = ""; strFindType mstrFindType =
(strFindType) MultiView1.ActiveViewIndex; switch(mstrFindType) { case strFindType.Products: DoSearch(textProductName.Text, mstrFindType); break; case strFindType.Category: DoSearch(textCategory.Text, mstrFindType); break; case strFindType.NotSet: break; } } }
protected void DoSearch(String strTerm, strFindType type) { // Code here to perform a search. } protected void radioButton_CheckedChanged(Object sender,
System.EventArgs e) { if(radioProduct.Checked) { MultiView1.ActiveViewIndex = (int) strFindType.Products; } else if(radioCategory.Checked) { MultiView1.ActiveViewIndex = (int) strFindType.Category; } }
-
in .aspx page,
-
<html><head id="Head1" runat="server"></head><body> <form id="form2" runat="server"> <div> Search by product or by category? <br /> <asp:RadioButton ID="radioProduct"
runat="server"
autopostback="true"
GroupName="SearchType"
Text="Product"
OnCheckedChanged="radioButton_CheckedChanged" />
<asp:RadioButton ID="radioCategory"
runat="server"
autopostback="true"
GroupName="SearchType"
Text="Category"
OnCheckedChanged="radioButton_CheckedChanged" /> <br /> <br /> <asp:MultiView ID="MultiView1" runat="server"> <asp:View ID="viewProductSearch" runat="server"> Enter product name:
<asp:TextBox ID="textProductName" runat="server"> </asp:TextBox> </asp:View> <asp:View ID="viewCategorySearch" runat="server"> Enter category:
<asp:TextBox ID="textCategory" runat="server"> </asp:TextBox> </asp:View> </asp:MultiView> <br /> <br /> <asp:Button ID="btnSearch"
OnClick="Button1_Click"
runat="server" Text="Search" /> </div> </form></body></html>
-
- Related Links
-
d1a7c07a-a90d-4682-a5fd-fc6be9d92e86|0|.0