469,925 Members | 1,493 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,925 developers. It's quick & easy.

Dynamic loading of Usercontrol problem


I am trying to create an webform which loads usercontrols
dyanamically. I know exactly what to load for some of these controls
but for some, I dont want to load it until the user has press a

The controls which I know I will need at page init gets their
viewstate contents back properly per postback. However I am having a
lot of troubles with keeping the contents of usercontrols which are
only loaded when user clicks on a button. They don't seem to keep
their contents entered by the user after a postback.

I know that you are supposed to loadcontrols at page_init , so I
thought that maybe it was due to loading of the usercontrol at the
button click event causing this problem. So I have moved it loading of
them to page_init on condition of a state set when user clicks on

Is this problem because of my instance of the usercontrol is not kept
for reloading, so in effect , I am loading a brand new control
everyttime? I have problems keeping reference of the userscontrol
between postback because I have a webfarm here, so I think thats the
reason for example caching not working to well.

I am having fierce troubles here. Can someone please shed some light
here? Share some sample code etc. The below is briefly what I am

Heres the code invloved. The RecreateControl is what I call from
page_init. This creates the necessary controls on page load on
postback. I am losing user input per psotback.

private void ReCreateControls()
if(btnEditProfile.Text == btnOn)


private void LoadProfile()
// Load the User Control
Control uc = LoadControl("EditProfile.ascx");
// Add the User Control to the Controls collection
private void LoadTicketInfo()
ArrayList TicketInfo = BLL.TicketInfo.GetTicketInfo(2);


//create ticket
foreach(BLL.TicketInfo ti in TicketInfo)

Control uc = LoadControl(ti.UserControlName);

// Add the User Control to the Controls collection
Control c = Page.FindContro(ti.PlaceHolderName);
Page.FindControl(ti.PlaceHolderName).Controls.Add( uc);


Nov 18 '05 #1
0 1358

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by tascien | last post: by
1 post views Thread by Sundaresan | last post: by
12 posts views Thread by Joe | last post: by
2 posts views Thread by Lloyd Sheen | last post: by
9 posts views Thread by pbd22 | last post: by
reply views Thread by =?Utf-8?B?Y2luZHk=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.