Apr 14, 2012

Adding a custom control Dynamically to a page in ASP.NET

Adding a custom control Dynamically to a page in ASP.NET

1. Create a control .ascx file into your project Header.ascx (say).

2. Then add a refrence to your control

<%@ Reference Control="~/modules/controls/Header.ascx"%>


3. Then in C# use below code
     (controls are listed in ASP namespace)
ASP.Header header_ctrl= (ASP.Header)LoadControl("~/Header.ascx"); 
Placeholder.Controls.Add(header_ctrl); 

here  Header is custom control and Placeholder is a panel.


No comments:

Post a Comment