Load User Control dynamically.

vishalneeraj-24503
Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 1379
With the help of LoadControl of Page class,we can dynamically Load any User Controls:-

For Example:-

protected void Page_Load(object sender, EventArgs e)
{
Control myCtrl = null;

myCtrl = Page.LoadControl("~/UserControls/UcTeamControl.ascx");

Page.Controls.Add(myCtrl);
}


UcTeamControl.ascx will look like this:-

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="UcTeamControl.ascx.vb" Inherits="UcTeamControl" %>
<table cellpadding="1" cellspacing="1">
<tr>
<td align="left" valign="middle">
<asp:Button ID="btn_new" runat="server" Text="New" />
<asp:Button ID="btn_Save" runat="server" Text="Save" />
<asp:Button ID="btn_reset" runat="server" Text="Reset" />
<asp:Button ID="btn_delete" runat="server" Text="Delete" />
</td>
</tr>
</table>

Comments or Responses

Login to post response