Dynamically Loaded User Controls

R

Rich

Hi,
I have been looking into how dynamical user controls work on asp.net web
pages.

This simple code is used to load and add the control to the page, which also
has a Label control.

TextBox tb = new TextBox();
this.Label1.Controls.Add(tb);

This code has been tried in both the 'Page_Load' and the 'OnInit' events of
the Page.

(I also have a button on the page to test if viewstate is maintained after a
postback.)
If I add text to the control ( after the page is loaded) and then click the
button to do a postback the text always stays the same.

Can someone tell me why the viewstate is maintianed in both cases? I thought
loading the control in the 'OnInit' event was the correct place to load
controls and to maintian its viestate?

Cheers
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top