Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: adding user control programatically

Reply
Thread Tools

Re: adding user control programatically

 
 
Shailesh Ratadia
Guest
Posts: n/a
 
      05-19-2004
Hi Francois,

Since a user control is dynamically generated, you cannot create the user
control programatically using new. You might want to try the LoadContol
method of the containing page which returns an object of type contol which
you can cast to the strong type of your user control.

Hope that helps.

-Shailesh Ratadia

"francois" <(E-Mail Removed)_NOSPAM> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I would like to add a USER control (not custom control) programmatically

to
> my aspx page.
> I am using something like the following in my page code :
>
> Bos.UserControls.HeaderFinance header = new HeaderFinance();
>
> this.Controls.Add(header);
>
> The problem is that asp.net controls existing in my user control are not
> instanciated and are still 'null', then of course it does not work.
>
> Then is there a way to add a user control to a page programatically? Or

at
> least dynamically. I want to add different user controls on my page
> depending of some runtime parameters.
>
> Best regards,
>
> Francois
>
>
>



 
Reply With Quote
 
 
 
 
francois
Guest
Posts: n/a
 
      05-20-2004
I have done it but now I have the following error :

The Controls collection cannot be modified because the control contains code
blocks (i.e. <% ... %>).

Does that mean that the user controls I add programatically are forbidden to
haveany <% %> tags? Or did I left out something?

Francois

"Shailesh Ratadia" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Francois,
>
> Since a user control is dynamically generated, you cannot create the user
> control programatically using new. You might want to try the LoadContol
> method of the containing page which returns an object of type contol which
> you can cast to the strong type of your user control.
>
> Hope that helps.
>
> -Shailesh Ratadia
>
> "francois" <(E-Mail Removed)_NOSPAM> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I would like to add a USER control (not custom control) programmatically

> to
> > my aspx page.
> > I am using something like the following in my page code :
> >
> > Bos.UserControls.HeaderFinance header = new HeaderFinance();
> >
> > this.Controls.Add(header);
> >
> > The problem is that asp.net controls existing in my user control are not
> > instanciated and are still 'null', then of course it does not work.
> >
> > Then is there a way to add a user control to a page programatically? Or

> at
> > least dynamically. I want to add different user controls on my page
> > depending of some runtime parameters.
> >
> > Best regards,
> >
> > Francois
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programatically adding a user control through code Ben Dewey ASP .Net 2 05-05-2006 09:16 PM
Dynamically Adding User Control with Child User Control Travis Pruitt ASP .Net Building Controls 0 01-13-2005 08:49 PM
Having trouble adding a web user control programatically. Shawn ASP .Net Building Controls 4 08-01-2004 12:53 PM
adding user control programatically francois ASP .Net 1 05-19-2004 01:52 PM
Programatically adding a control (DataGrid)? AC ASP .Net 0 01-05-2004 07:51 PM



Advertisments