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