Page.LoadControl

G

Guest

Hi all
I have one page WebForm1.aspx and one user control UserControl.ascx
My WebForm1 has a Place holder and dropdownlist with autopostback property
set to true.

The user control also has a dropdownlist with autopostback property to true

One selecting Item1 from dropdownlist on Webform1 I want the user control to
be added to the place holder.
This works fine.

But when i select an item from the dropdownlist of the usercontrol, the user
control is not loaded.

So on any post back of the user control , I dont see the usercontrol on the
page

What should i do to see the usercontrol on the page all times

Thanks
Sekhar
 
K

Kevin Spencer

Every time the Page is posted back, the entire page and everything in it
must be created. Therefore, if you add any Control to the Page during a
PostBack, you have to re-add it and restore its state with each successive
PostBack.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
G

Guest

Hi,

All dynamically created controls need to be recreated on every post back.
This should be done in the page_init or page_load event. This is because on
post back the web server has no idea of any previously dynamically created
controls.

Once they are recreated its methods will then be invoked.

See the page lifecycle: http://msdn2.microsoft.com/en-US/library/ms178472.aspx

Regards
Warren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top