MultiView and View for ASP. NET Server controls

Source: Internet
Author: User

MultiView and View controls are used to create tabs. MultiView controls are containers of a group of View Controls. You can use it to define a group of View Controls. Each View Control contains child controls.

To switch the View, you can use the control ID or View control index value. InMultiViewControl, only oneViewControls are defined as activity views. IfViewThe control is defined as an activity view. Its Child control is displayed on the client. You can use the ActiveViewIndex attribute or the SetActiveView method to define the activity view. IfActiveViewIndexIf the property is nullMultiViewControls do not render any content to the client. If the activity view is setMultiViewTheView, ArgumentOutOfRangeException will be thrown at runtime.

 

Some common attributes and methods:

ActiveViewIndexAttribute: used to obtain or set the index value of the currently activated View control. The default value is-1, indicating that no View control is activated.

 

As MultiView and View are relatively simple, let's take a look at the following example.

 

 

Create a new ASP. NETWebsite project

1. In the "file" menu, point to "new" and select "website ".

2. In the "New Website" dialog box, select Visual C # From the "language" drop-down list and select an ASP. NET website template.

3. In "location", select HTTP and type the website URL. The default URL is http: // localhost/WebSite. Change to http: // localhost/MultiViewTest and click OK ".

 

4. Open the Default. aspx designer, switch to the code area, select Ctrl + A, and replace it with the following code:

[C-sharp]View plaincopy
  1. <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
  2. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <Html xmlns = "http://www.w3.org/1999/xhtml">
  4. <Head runat = "server">
  5. <Title> No title page </title>
  6. </Head>
  7. <Body>
  8. <Form id = "form1" runat = "server">
  9. <Div>
  10. <Asp: LinkButton ID = "LinkButton1" runat = "server" onclick = "LinkButton1_Click"> first </asp: LinkButton>
  11. <Asp: LinkButton ID = "LinkButton2" runat = "server" onclick = "LinkButton2_Click"> second </asp: LinkButton>
  12. <Asp: LinkButton ID = "LinkButton3" runat = "server" onclick = "LinkButton3_Click"> third </asp: LinkButton>
  13. <Br/>
  14. <Hr/>
  15. <Asp: MultiView ID = "MultiView1" runat = "server" ActiveViewIndex = 1>
  16. <Asp: View ID = "View1" runat = "server">
  17. This is the first page
  18. </Asp: View>
  19. <Asp: View ID = "View2" runat = "server">
  20. This is the second page
  21. </Asp: View>
  22. <Asp: View ID = "View3" runat = "server">
  23. This is the third page
  24. </Asp: View>
  25. </Asp: MultiView>
  26. </Div>
  27. </Form>
  28. </Body>
  29. </Html>

 

 

Explanation of the above Code:

The MultiView and View Web server controls are used as containers for other controls and tags, and provide a way to conveniently display information to replace the View.

MultiViewControls are used as one or moreViewThe external container of the control.ViewControls can contain any combination of tags and controls.

MultiViewControl displays oneViewControl, and publishViewIn the widget. SetMultiViewThe ActiveViewIndex attribute of the control. You can specify the currently visibleViewControl.

 

In short, MultiView is a parent container, which includes three View containers. The View container with the index specified by ActiveViewIndex = 1 is displayed, and the other two are hidden. (The index starts from 0 in the order of view)

 

 

 

5. Open Default. aspx. cs, press Ctrl + A to select all, and then replace it with the following code:

 

 

[C-sharp]View plaincopy
  1. Using System;
  2. Using System. Configuration;
  3. Using System. Data;
  4. Using System. Linq;
  5. Using System. Web;
  6. Using System. Web. Security;
  7. Using System. Web. UI;
  8. Using System. Web. UI. HtmlControls;
  9. Using System. Web. UI. WebControls;
  10. Using System. Web. UI. WebControls. WebParts;
  11. Using System. Xml. Linq;
  12. Public partial class _ Default: System. Web. UI. Page
  13. {
  14. Protected void Page_Load (object sender, EventArgs e)
  15. {
  16. }
  17. Protected void linkbutton#click (object sender, EventArgs e)
  18. {
  19. This. MultiView1.ActiveViewIndex = 0;
  20. }
  21. Protected void LinkButton2_Click (object sender, EventArgs e)
  22. {
  23. This. MultiView1.ActiveViewIndex = 1;
  24. }
  25. Protected void LinkButton3_Click (object sender, EventArgs e)
  26. {
  27. This. MultiView1.ActiveViewIndex = 2;
  28. }
  29. }

 

 

6. Save and press Ctrl + F5 to start running. If everything goes well, you can see the following interface:


Click the first, second, and third tabs to switch 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.