09 - Working With User Control
09 - Working With User Control
Agenda
1
Deccansoft Software Services - ASP.NET User Controls
2
Deccansoft Software Services - ASP.NET User Controls
{
lblCaption.Text = value;
}
}
}
Code: 1.5 C#
Step 3: Add a Web Form to the Application (Default.aspx)
Step 4: Drag HelloUser Control from Solution explorer and on the design view of the Web Form. This adds the
following to the Web Form (Default.aspx).
<%@ Register Src="HelloControl.ascx" TagName="HelloControl" TagPrefix="uc1" %>
Step 5: Add another User Control and change the Id to “hcName” and “hcFathersname”. Also add a button to the
Web Form.
Using User Control
<uc1:HelloControl ID="hcName" runat="server" Caption=”Your Name” RealName="Test Test"/>
<uc1:HelloControl ID="hcFathersName" runat="server" RealName="Z Y" Caption="Fathers Name"/>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"/>
Step 6:
Handling btnSubmit click event
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Write(hcName.RealName);
Response.Write("<br>" + hcFathersName.RealName);
}
Code: 1.5 C#
Page.ClientScript Class
The above function renders the Javascript code (including the script tag) only once irrespective of number of times
the above line is executed
This should be written in Page_Load event of User Control in situations where multiple instances of User Control will
be included in the Web Form.