blog

Home / DeveloperSection / Blogs / Multiview in ASP.NET

Multiview in ASP.NET

priyanka kushwaha2687 18-Feb-2015

In this blog, I’m explaining about Multiview in .Net


The Multiview acts like a standalone controls  It is a container that can hold various “view” controls. And the “view” control can hold any number of other controls, the benefit is they are group together, so that its easy  to provide visibility. 


Example

1.      Create a .aspx file

 
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Multiview.aspx.cs"Inherits="MultiviewsTopic.Multiview"%>
 
<!DOCTYPEhtml>
 
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
    <title></title>
</head>
<body>
    <formid="form1"runat="server">
        <div>
            <tableborder="0"cellpadding="2"cellspacing="3"width="100%">
 
                <tr>
                    <td>
                        <asp:LinkButtonID="lnkTab1"runat="server"OnClick="lnkTab1_Click">Tab1</asp:LinkButton></td>
                    <td>
                        <asp:LinkButtonID="lnkTab2"runat="server"OnClick="lnkTab2_Click">Tab2</asp:LinkButton></td>
                    <td>
                        <asp:LinkButtonID="lnkTab3"runat="server"OnClick="lnkTab3_Click">Tab3</asp:LinkButton></td>
                </tr>
                <tr>
                    <tdcolspan="3">
                        <asp:MultiViewID="MultiView1"runat="server">
                            <tablewidth="100%"cellpadding="2"cellspacing="5">
                                <tr>
                                    <td>
                                        <asp:ViewID="View1"runat="server">
                                            <table>
                                                <tr>
                                                    <td>User Name</td>
                                                    <td>
                                                        <asp:TextBoxID="TextBox1"runat="server"></asp:TextBox></td>
                                                </tr>
                                                <tr>
                                                    <td>Password</td>
 
                                                    <td>
                                                        <asp:TextBoxID="TextBox2"runat="server"></asp:TextBox></td>
                                                </tr>
                                                <tr>
                                                    <tdcolspan="2">
                                                        <asp:ButtonID="btn"runat="server"Text="Submit"/></td>
                                                </tr>
                                            </table>
                                        </asp:View>
                                    </td>
                    <td>
                        <asp:ViewID="View2"runat="server">
                            <divstyle="width: 100%;">
                                <asp:ScriptManagerID="ScriptManager1"runat="server"/>
                                <asp:TimerID="Timer1"Interval="2000"runat="server"/>
                                <asp:UpdatePanelID="up1"runat="server">
                                    <Triggers>
                                        <asp:AsyncPostBackTriggerControlID="Timer1"EventName="Tick"/>
                                    </Triggers>
                                    <ContentTemplate>
                                        <asp:AdRotator
                                            ID="AdRotator1"
                                            AdvertisementFile="~/XMLFile.xml"
                                            runat="server"Target="_top"Width="500px"/>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </div>
                        </asp:View>
                    </td>
                    <td>
                        <asp:ViewID="View3"runat="server">
                            content 3 goes here
                        </asp:View>
                    </td>
                </tr>
                </table>
                        </asp:MultiView></td>
                </tr>
            </table>
            <div>
            </div>
        </div>
    </form>
</body>
</html>

 

 

Write in .cs file

 

namespace MultiviewsTopic
{
    publicpartialclassMultiview : System.Web.UI.Page
    {
        protectedvoid Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetDefaultView();
            }
        }
        privatevoid SetDefaultView()
        {
            MultiView1.ActiveViewIndex = 0;
            MultiView1.SetActiveView(View2);
        }
 
        protectedvoid lnkTab1_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 0;
        }
 
        protectedvoid lnkTab2_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }
 
        protectedvoid lnkTab3_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 2;
        }
 
    }
}

 

2.     Create a XML file 

<?xmlversion="1.0"encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>~/images/A.jpg</ImageUrl>
    <width>40px </width>
    <height>50px</height>
    <NavigateUrl>http://www.pastelspace.com/image_detail.php?id=1228</NavigateUrl>
 
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small1</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/images/B.jpg</ImageUrl>
    <width>40px </width>
    <height>50px</height>
    <NavigateUrl>http://www.pastelspace.com/image_detail.php?id=1034</NavigateUrl>
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small2</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/images/C.jpg</ImageUrl>
    <width>40px</width>
    <height>50px</height>
    <NavigateUrl>http://www.dotnetcurry.com</NavigateUrl>
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small</Keyword>
  </Ad>
</Advertisements>

 

Output:
 

Multiview in ASP.NET

Multiview in ASP.NET


Updated 18-Feb-2015

Leave Comment

Comments

Liked By