Rabu, 07 Agustus 2013

How to use web User Control in ASP.NET

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 .

How to use web User Control in ASP.NET

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 .
How to use web User Control in ASP.NET


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

<%@ Control Language="C#" ClassName="WebUserControl" %>
<script runat="server">
</script>
<asp:Label ID="Label1" runat="server" Text="UserName"></asp:Label>
&nbsp;:
<asp:TextBox ID="TextBox1" runat="server" Width="189px"></asp:TextBox>
<p>    &nbsp;</p>
<p>    Password :&nbsp;
    <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


<%@ 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>

Tidak ada komentar:

Posting Komentar