How to add Webusercontol Dynamailly in the Page

Posted by Rkumar670 under ASP.NET on 5/1/2010 | Views : 1325 | Status : [Member] | Replies : 3
Hi All,


When I Trying to Add the Webusercontrol.ascx in my Web site dynamically the .net intellgence not show the name of the control. but when i am adding in webapplication it is working.
So please tell me how to add webusercontrol in my website....

My Code is


on page load..

Webusercontrol web = webusercontrol)Loadcontrol("~/webusercontrol.ascx");
form1.Controls.Add(web);


this code is working on web application but not in the wesite.....




Responses

Posted by: Raja on: 5/1/2010 [Member] Starter

Up
0
Down
Hi,

You can read this code snippet http://www.dotnetfunda.com/codes/code533-add-a-web-user-control-dynamically-at-runtime.aspx.

Thank you.



Regards,
Raja, USA

Rkumar670, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Er.deepakdalal on: 5/2/2010 [Member] Starter

Up
0
Down
Hi Rkumar670



Try this link or the attached sample of dynamically Add and Remove User Control from the Web Form...


http://www.codeproject.com/KB/user-controls/DynamicUC.aspx


Its really help me, i hope your problem is also solved out.
 Download source file

Rkumar670, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naveenmanam on: 5/4/2010 [Member] Starter

Up
0
Down
We can add a Web User Control Dynamically (At Runtime) in 2 steps.

Step 1 : Add a "PlaceHolder" in your aspx page.

<body>

<form id="form1" runat="server">

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

</form>

</body>



Step 2 : Write the following code on page load (Code Behind).

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim UCDynamic As Control

'WebUserControl.ascx : User Control path

UCDynamic = LoadControl("WebUserControl.ascx")

PlaceHolder1.Controls.Add(UCDynamic)

End Sub



Regards,

NaveenKumar

Rkumar670, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response