P
Phl
Hi,
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
button.
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
button.
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
doing:
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)
{
LoadProfile();
}
LoadTicketInfo();
}
private void LoadProfile()
{
// Load the User Control
Control uc = LoadControl("EditProfile.ascx");
// Add the User Control to the Controls collection
PlaceHolder.Controls.Add(uc);
}
private void LoadTicketInfo()
{
ArrayList TicketInfo = BLL.TicketInfo.GetTicketInfo(2);
Page.FindControl("TicketInfoph").Controls.Clear();
//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);
}
}
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
button.
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
button.
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
doing:
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)
{
LoadProfile();
}
LoadTicketInfo();
}
private void LoadProfile()
{
// Load the User Control
Control uc = LoadControl("EditProfile.ascx");
// Add the User Control to the Controls collection
PlaceHolder.Controls.Add(uc);
}
private void LoadTicketInfo()
{
ArrayList TicketInfo = BLL.TicketInfo.GetTicketInfo(2);
Page.FindControl("TicketInfoph").Controls.Clear();
//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);
}
}