How do I add a user control on page load dynamically in ASP.NET?
I have a div with ID="contentData" and few controls
- one.ascx
- two.ascx
- three.ascx
Now I have created a page default.aspx, which may get parameters in query string, in one of the following ways:
default.aspx?val=one
default.aspx?val=two
default.aspx?val=three
I am taking the value from
Request.QueryString["val"]
Now how do I load specific control in this?
<div ID="controlData"></div>
In your aspx
In Page_Load
All you need to do is make your div server bound by adding runat=”server”, and in the codebehind use Page.LoadControl to go out and fetch your usercontrol and then add it to your div using the div’s Controls.Add