Asp. NET MultiView and View tab controls how to use _ Basic application

Source: Internet
Author: User

The MultiView control can be used as an external container for one or more View controls. The View control can contain any combination of markup and controls. You can use the MultiView and View controls to perform various tasks, such as providing alternate control sets based on user selection or creating multi-page forms.

The MultiView control displays one view control at a time and exposes the tags and controls within the view control. You can specify the View control that is currently visible by setting the ActiveViewIndex property of the MultiView control.

If you want to switch views, you can use the ID of the control or the index value of the view control. In a MultiView control, you can define only one view control as the active view at a time. If a view control is defined as an active view, the child controls it contains are rendered to the client. You can use the ActiveViewIndex property or the SetActiveView method to define the active view. If the ActiveViewIndex property is empty, the MultiView control does not render any content to the client. If the active view is set to a view that does not exist in the MultiView control, ArgumentOutOfRangeException is thrown at run time.

That's a little bit of crap, just an example.

Create a new ASP.net web site project

1. On the File menu, point to New, and then select Web site.

2. In the New Web Site dialog box, select Visual C # from the Language Drop-down list and select the ASP.net site template.

3. In location, select HTTP and type the URL of the Web site. The default URL is Http://localhost/WebSite. Change to Http://localhost/MultiViewTest, and click OK.

4. Open Default.aspx Designer, switch to code area, CTRL + A Select all, replace with the following code:

Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:linkbutton id= "LinkButton1" runat= "Server" onclick= "LinkButton1_Click" >first</asp:LinkButton>
<asp:linkbutton id= "LinkButton2" runat= "Server" onclick= "Linkbutton2_click" >second</asp:LinkButton>
<asp:linkbutton id= "LinkButton3" runat= "Server" onclick= "Linkbutton3_click" >third</asp:LinkButton>
<br/>
<asp:multiview id= "MultiView1" runat= "server" ActiveViewIndex = 1>
<asp:view id= "View1" runat= "Server" >
This is the page
</asp:View>
<asp:view id= "View2" runat= "Server" >
This is the second page
</asp:View>
<asp:view id= "VIEW3" runat= "Server" >
This is the third page
</asp:View>
</asp:MultiView>
</div>
</form>
</body>

Explanation of the above code:

The MultiView and view Web server controls act as containers for other controls and tags, and provide a way to easily display alternate views of information.

The MultiView control acts as an external container for one or more View controls. The View control can also contain any combination of markup and controls.

The MultiView control displays one view control at a time and exposes the tags and controls within the view control. You can specify the View control that is currently visible by setting the ActiveViewIndex property of the MultiView control.

Simply put, MultiView is a parent container that includes 3 view containers. The Activeviewindex=1 property indicates that the view container with index 1 is displayed, and the other two are hidden. (index is arranged in the order of view starting from 0)

5. Open Default.aspx.cs and press CTRL + A to select all, and replace with the following code after deletion:

Copy Code code as follows:

Using System;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;

public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{

}
protected void LinkButton1_Click (object sender, EventArgs e)
{
This. Multiview1.activeviewindex = 0;
}
protected void Linkbutton2_click (object sender, EventArgs e)
{
This. Multiview1.activeviewindex = 1;
}
protected void Linkbutton3_click (object sender, EventArgs e)
{
This. Multiview1.activeviewindex = 2;
}
}

6. After saving press Ctrl+f5 to start running, if all goes well, you can see the following interface:


Click the First,second,third tab to toggle the content.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.