Load User Control dynamically.

Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 633
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");


UcTeamControl.ascx will look like this:-

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="UcTeamControl.ascx.vb" Inherits="UcTeamControl" %>
<table cellpadding="1" cellspacing="1">
<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" />

Comments or Responses

Login to post response