Example of Web User Control
Step-1 : Add Web User Control file in solution explorer name as " WebUserControl.ascx".
Step-2 : Drop some controls from tool box to Designing window of WebUserControl.ascx page .
Step-1 : Add Web User Control file in solution explorer name as " WebUserControl.ascx".
Step-2 : Drop some controls from tool box to Designing window of WebUserControl.ascx page .
Step-3 : Add a Web form in Solution explorer name as " usercontroluses.aspx"
Step-4 : Drop "WebUserControl.ascx " page from solution explorer to Web form ( usercontroluses.aspx)
Step-5 : Check your Web Form designing part .
After dropping your web form contain a single Register directive and one user defined tag.
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
Code file of WebUserControl.ascx<uc1:WebUserControl ID="WebUserControl1" runat="server" />
<%@ Control Language="C#" ClassName="WebUserControl" %>
<script runat="server">
</script>
<asp:Label ID="Label1" runat="server" Text="UserName"></asp:Label>
:
<asp:TextBox ID="TextBox1" runat="server" Width="189px"></asp:TextBox>
<p> </p>
<p> Password :
<asp:TextBox ID="TextBox2" runat="server" Width="192px"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Submit " />
</p>
Code file of usercontroluses.aspx<script runat="server">
</script>
<asp:Label ID="Label1" runat="server" Text="UserName"></asp:Label>
:
<asp:TextBox ID="TextBox1" runat="server" Width="189px"></asp:TextBox>
<p> </p>
<p> Password :
<asp:TextBox ID="TextBox2" runat="server" Width="192px"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Submit " />
</p>
<%@ Page Language="C#" %>
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
</div>
</form>
</body>
</html>
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
</div>
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar