Home > DeveloperSection > Blogs > Multiview in ASP.NET

Multiview in ASP.NET


.NET C#  ASP.Net 
Ratings:
0 Comment(s)
 714  View(s)
Rate this:

Multiview in ASP.NET

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

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Multiview.aspx.cs" Inherits="MultiviewsTopic.Multiview" %>

 

<!DOCTYPE html>

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <table border="0" cellpadding="2" cellspacing="3" width="100%">

 

                <tr>

                    <td>

                        <asp:LinkButton ID="lnkTab1" runat="server" OnClick="lnkTab1_Click">Tab1</asp:LinkButton></td>

                    <td>

                        <asp:LinkButton ID="lnkTab2" runat="server" OnClick="lnkTab2_Click">Tab2</asp:LinkButton></td>

                    <td>

                        <asp:LinkButton ID="lnkTab3" runat="server" OnClick="lnkTab3_Click">Tab3</asp:LinkButton></td>

                </tr>

                <tr>

                    <td colspan="3">

                        <asp:MultiView ID="MultiView1" runat="server">

                            <table width="100%" cellpadding="2" cellspacing="5">

                                <tr>

                                    <td>

                                        <asp:View ID="View1" runat="server">

                                            <table>

                                                <tr>

                                                    <td>User Name</td>

                                                    <td>

                                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>

                                                </tr>

                                                <tr>

                                                    <td>Password</td>

 

                                                    <td>

                                                        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>

                                                </tr>

                                                <tr>

                                                    <td colspan="2">

                                                        <asp:Button ID="btn" runat="server" Text="Submit" /></td>

                                                </tr>

                                            </table>

                                        </asp:View>

                                    </td>

                    <td>

                        <asp:View ID="View2" runat="server">

                            <div style="width: 100%;">

                                <asp:ScriptManager ID="ScriptManager1" runat="server" />

                                <asp:Timer ID="Timer1" Interval="2000" runat="server" />

                                <asp:UpdatePanel ID="up1" runat="server">

                                    <Triggers>

                                        <asp:AsyncPostBackTrigger ControlID="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:View ID="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

{

    public partial class Multiview : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                SetDefaultView();

            }

        }

        private void SetDefaultView()

        {

            MultiView1.ActiveViewIndex = 0;

            MultiView1.SetActiveView(View2);

        }

 

        protected void lnkTab1_Click(object sender, EventArgs e)

        {

            MultiView1.ActiveViewIndex = 0;

        }

 

        protected void lnkTab2_Click(object sender, EventArgs e)

        {

            MultiView1.ActiveViewIndex = 1;

        }

 

        protected void lnkTab3_Click(object sender, EventArgs e)

        {

            MultiView1.ActiveViewIndex = 2;

        }

 

    }

}

 

2.      Create a XML file

 

<?xml version="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:

 


Don't want to miss updates? Please click the below button!

Follow MindStick