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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top