Multiview in asp.net
Here by this article we learn how to use Multiview and View in asp.net
Multiview is very usefull you can use it instead of content pages for master pages.
First
Write this code in asp.net first page
Default.aspx:
<%@ 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â>
<html xmlns=âhttp://www.w3.org/1999/xhtmlâ>
<head runat=âserverâ>
<title>View Control Example</title>
</head>
<body>
<form id=âFormâ runat=âserverâ>
<div id=âheaderâ>
<h1>
ASP.NET Multiview
</h1>
</div>
<div id=âsidebarâ>
<div id=ânavâ>
</div>
</div>
<div id=âcontentâ>
<div class =âitemContentâ >
<div>
<asp:Label ID=âLabel1? runat=âserverâ Font-Bold=âTrueâ
Font-Size=âMediumâ
Font-Underline=âTrueâ Text=âView and MultiView Controls Exampleâ></asp:Label>
<br />
<br />
<asp:Button id=âButton1? runat=âserverâ Text=âClick Me to See View1?
OnClick=âButton1_Clickâ BackColor=âBlackâ ForeColor=â#00CCFFâ />
<asp:Button id=âButton2? runat=âserverâ Text=âClick Me to See View2?
OnClick=âButton2_Clickâ BackColor=âBlackâ ForeColor=â#00CCFFâ />
<asp:Button id=âButton3? runat=âserverâ Text=âClick Me to See View3?
OnClick=âButton3_Clickâ BackColor=âBlackâ ForeColor=â#00CCFFâ />
<br /><br />
<asp:MultiView id=âMultiView1? runat=âserverâ ActiveViewIndex=0>
<asp:View id=âView1? runat=âserverâ>
<a style=âfont-family: âTimes New Romanâ, Times, serifâ>I am Dwayne</a> <br />
<br />
<asp:Image ID=âImage1? runat=âserverâ Height=â132pxâ ImageUrl=âdwaynejohnson.jpgâ Width=â92pxâ />
<br />
</asp:View>
<asp:View id=âView2? runat=âserverâ>
<a style=âfont-family: âTimes New Romanâ, Times, serifâ >I am Nikhil</a>
<br />
<br />
<asp:Image ID=âImage2? runat=âserverâ ImageUrl=âMy pic.jpgâ/>
</asp:View>
<asp:View id=âView3? runat=âserverâ>
<a style=âfont-family: âTimes New Romanâ, Times, serifâ>I am a progress bar</a>
<br />
<br />
<asp:Image ID=âImage3? runat=âserverâImageUrl=âLoading1.gifâ />
</asp:View>
</asp:MultiView>
<br />
<br />
<br />
<br />
<br />
<div id=âfooterâ>
</div>
</div>
</div>
</div>
</form>
</body>
</html> |
Declaration:
Here we are creating three buttons for three views(under MultiView Control)
All buttons are changing the view and evrey view is having another contents
Here you have to paste three images in your solution explorer I have used here
1- dwaynejohnson.jpg
2- My pic.jpg
3- Loading1.gif
We have created One MultiView control and three View controls under Multiview control.
Note: You can use many View controls under MultiView controls as per your requirements.
Under view controls we are using image controls
You can use anycontrol which you want in place of image control.
Second:
Now add this code
Default.aspx.cs:
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)
{
MultiView1.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.Visible = true;
MultiView1.SetActiveView(View1);
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.Visible = true;
MultiView1.SetActiveView(View2);
}
protected void Button3_Click(object sender, EventArgs e)
{
MultiView1.Visible = true;
MultiView1.SetActiveView(View3);
}
} |
Declaration:
Here on the page loading the Multiview is invisible
When you click the first button it will show the first view control
When you click the second button it will show the second view control
When you click the third button it will show the third view control
SetActiveView is using for set the active view.
Interface:
![MultiView.JPG]()
Conclusion:
Here we learn how to use MultiView control in asp.net which works like a master page and its content pages.
If you feel help then contact me I will be happy to help you âŠ
Thanks
Nikhil Kumar