Live Chat Icon For mobile
Live Chat Icon

How to dynamically load User Controls

Platform: ASP.NET| Category: User Controls

Create a User Control


<P>
<asp:Button id='Button1' runat='server' Text='Button'></asp:Button></P>
<P>
<asp:Label id='Label1' runat='server'></asp:Label></P>

On button Click
VB.NET


Label1.Text = 'Hello' 

C#


Label1.Text = 'Hello' ;

Create a Webform to use a UserControl


<asp:Panel id='Panel1' runat='server'></asp:Panel>

VB.NET


Dim myControl As Control = CType(Page.LoadControl('UC1.ascx'), Control)
Panel1.Controls.Add(myControl)

C#


Control myControl   =(Control)Page.LoadControl('UC1.ascx');
Panel1.Controls.Add(myControl);

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.