LoadControl user control : Basics « User Control and Master Page « ASP.Net






LoadControl user control


<%@ Page %>
<%@ Reference Control="control.ascx" %>
<script runat="server" language="C#">
void Page_Load(Object sender, EventArgs e)
{
    Control sampleControl = LoadControl("Control.ascx");
    Controls.Add(sampleControl);
}
</script>

C# version (control.ascx)


<%@ Control Language="C#" %>
<script runat="server" language="C#">
void Page_Load(Object sender, EventArgs e)
{
    AuthorLabel.Text = "Sample Control Text";
}
</script>
<h3><asp:Label id="AuthorLabel" runat="server" />

 








Related examples in the same category

1.Implementing a User Control on an ASP.NET Page (VB.net)
2.User control with no user interface (VB.net)
3.User control with asp control