[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

dynamically create multiple instances of usercontrol in codebehind

Padam

8/28/2007 5:12:00 AM

I created a user conrolt in C# and want to create multiple instance (one by
one) of usercontrol onclick of button. if i hard code in .aspx page like

<%@ Register Src="~/UserControls/AddPhaseMilestone.ascx"
TagName="AddPhaseMilestone" TagPrefix="uc1" %>

<uc1:AddPhaseMilestone ID="AddPhaseMilestone1" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone2" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone3" EnableViewState="true"
runat="server" />

<uc1:AddPhaseMilestone ID="AddPhaseMilestone4" EnableViewState="true"
runat="server" />

it works fine. I have to do in codebehind using click event to button. Pls
do suggest me how to do that. I tried below mention code but it is not
solving my problem.



Control oControl = Page.LoadControl("~/UserControls/AddPhaseMilestone.ascx");

//oControl.ID = "fajkla";

//PlaceHolder1.Controls.Add(oControl);

//div.Controls.Add(oControl);

Page.Controls.Add(oControl);

pls suggest some alternative solutions also, if possible

6 Answers

Riki

8/28/2007 7:46:00 AM

0

Padam wrote:
> I created a user conrolt in C# and want to create multiple instance
> (one by one) of usercontrol onclick of button. if i hard code in
> .aspx page like
>
> <%@ Register Src="~/UserControls/AddPhaseMilestone.ascx"
> TagName="AddPhaseMilestone" TagPrefix="uc1" %>
>
> <uc1:AddPhaseMilestone ID="AddPhaseMilestone1" EnableViewState="true"
> runat="server" />
>
> <uc1:AddPhaseMilestone ID="AddPhaseMilestone2" EnableViewState="true"
> runat="server" />
>
> <uc1:AddPhaseMilestone ID="AddPhaseMilestone3" EnableViewState="true"
> runat="server" />
>
> <uc1:AddPhaseMilestone ID="AddPhaseMilestone4" EnableViewState="true"
> runat="server" />
>
> it works fine. I have to do in codebehind using click event to
> button. Pls do suggest me how to do that. I tried below mention code
> but it is not solving my problem.
>
>
>
> Control oControl =
> Page.LoadControl("~/UserControls/AddPhaseMilestone.ascx");
>
> //oControl.ID = "fajkla";
>
> //PlaceHolder1.Controls.Add(oControl);
>
> //div.Controls.Add(oControl);
>
> Page.Controls.Add(oControl);
>
> pls suggest some alternative solutions also, if possible

This code is all right.
Why is it not solving your problem?
What is your problem?

--

Riki


Padam

8/28/2007 2:06:00 PM

0

It is not working when i create instances of user control in code behind.
padam

"Riki" wrote:

> Padam wrote:
> > I created a user conrolt in C# and want to create multiple instance
> > (one by one) of usercontrol onclick of button. if i hard code in
> > .aspx page like
> >
> > <%@ Register Src="~/UserControls/AddPhaseMilestone.ascx"
> > TagName="AddPhaseMilestone" TagPrefix="uc1" %>
> >
> > <uc1:AddPhaseMilestone ID="AddPhaseMilestone1" EnableViewState="true"
> > runat="server" />
> >
> > <uc1:AddPhaseMilestone ID="AddPhaseMilestone2" EnableViewState="true"
> > runat="server" />
> >
> > <uc1:AddPhaseMilestone ID="AddPhaseMilestone3" EnableViewState="true"
> > runat="server" />
> >
> > <uc1:AddPhaseMilestone ID="AddPhaseMilestone4" EnableViewState="true"
> > runat="server" />
> >
> > it works fine. I have to do in codebehind using click event to
> > button. Pls do suggest me how to do that. I tried below mention code
> > but it is not solving my problem.
> >
> >
> >
> > Control oControl =
> > Page.LoadControl("~/UserControls/AddPhaseMilestone.ascx");
> >
> > //oControl.ID = "fajkla";
> >
> > //PlaceHolder1.Controls.Add(oControl);
> >
> > //div.Controls.Add(oControl);
> >
> > Page.Controls.Add(oControl);
> >
> > pls suggest some alternative solutions also, if possible
>
> This code is all right.
> Why is it not solving your problem?
> What is your problem?
>
> --
>
> Riki
>
>
>

Jens Wefer

8/28/2007 3:59:00 PM

0

you must also load dynamically usercontrols after a postback.
Padam schrieb:
> It is not working when i create instances of user control in code behind.
> padam
>
> "Riki" wrote:
>
>> Padam wrote:
>>> I created a user conrolt in C# and want to create multiple instance
>>> (one by one) of usercontrol onclick of button. if i hard code in
>>> .aspx page like
>>>
>>> <%@ Register Src="~/UserControls/AddPhaseMilestone.ascx"
>>> TagName="AddPhaseMilestone" TagPrefix="uc1" %>
>>>
>>> <uc1:AddPhaseMilestone ID="AddPhaseMilestone1" EnableViewState="true"
>>> runat="server" />
>>>
>>> <uc1:AddPhaseMilestone ID="AddPhaseMilestone2" EnableViewState="true"
>>> runat="server" />
>>>
>>> <uc1:AddPhaseMilestone ID="AddPhaseMilestone3" EnableViewState="true"
>>> runat="server" />
>>>
>>> <uc1:AddPhaseMilestone ID="AddPhaseMilestone4" EnableViewState="true"
>>> runat="server" />
>>>
>>> it works fine. I have to do in codebehind using click event to
>>> button. Pls do suggest me how to do that. I tried below mention code
>>> but it is not solving my problem.
>>>
>>>
>>>
>>> Control oControl =
>>> Page.LoadControl("~/UserControls/AddPhaseMilestone.ascx");
>>>
>>> //oControl.ID = "fajkla";
>>>
>>> //PlaceHolder1.Controls.Add(oControl);
>>>
>>> //div.Controls.Add(oControl);
>>>
>>> Page.Controls.Add(oControl);
>>>
>>> pls suggest some alternative solutions also, if possible
>> This code is all right.
>> Why is it not solving your problem?
>> What is your problem?
>>
>> --
>>
>> Riki
>>
>>
>>

hy_biscus

7/1/2010 8:17:00 AM

0

I pretend you don't exist.
That way, I love you better.
Oh ya. I feel better than James Brown.


Aine wrote:

Aine

7/1/2010 9:28:00 AM

0

On Jul 1, 1:17 am, hy <"(hy)hy_biscus"@hotmail.com> wrote:
> I pretend you don't exist.
> That way, I love you better.
> Oh ya. I feel better than James Brown.
>
>
>
> Aine wrote:- Hide quoted text -
>
> - Show quoted text -

Yet you reply to my posts. Fruitloop.

Lady Azure, Baroness of the North Pole

7/2/2010 3:01:00 AM

0



Aine wrote:

> On Jul 1, 1:17 am, hy <"(hy)hy_biscus"@hotmail.com> wrote:
> > I pretend you don't exist.
> > That way, I love you better.
> > Oh ya. I feel better than James Brown.
> >
> >
> >
> > Aine wrote:- Hide quoted text -
> >
> > - Show quoted text -
>
> Yet you reply to my posts. Fruitloop.

Ren/Sid Game???