How do I save state?

L

landers

Dear All,

I have got a page with a user control (control1) already loaded using the
Register directive. When an event is raised from the user control, I use
LoadControl to show another user control (control2) on the screen. If
control2 raises events, how do I handle them? When the postback occurs,
original event from control1 has not been reraised, so the LoadControl
method is not executed!

Landers
 
G

Guest

1- Register Control2 and add a markup to it within the markup of Control1 but
turn its Visible property to true or false based on different events.
2- If you load Control2 within the event handling of control1 then save the
Session a variable that allows you to reload Control2 within the Init event
handling of Control1, e.g.
//put a line like this when you loaded the control
Session("WasControl2Loaded") = true;

//in the init event handling of control2 put code similar to this
if (Page.IsPostBack)
{
bool WasControl2Loaded = Session("Control2Loaded") as bool ;
if (WasControl2Loaded) { Page.LoadControl("Control2.ascx"); }
}
This is a simplified proof of concept:
http://www.societopia.net/Samples/DynamicallyCreatedControls.aspx
And this is an example where I used the first strategy above
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx
 
L

landers

Thanks Phillip. I had actually thought of those, but came to the conclusion
that solution one has a performance issue as there maybe a lots of controls
on the page, and solution two is a work around. When I say "Work around", I
mean surely Microsoft did not mean for us to be putting flags in Session
variables when there is this supposedly lovely Viewstate available?

If anyone has anyother solutions, they are more than welcome.

Landers
 
L

landers

Thanks again Phillip.

The first article is very useful.

I have noticed that when you turn page tracing on, there is a Form
Collection section. I have had a look at the Page.Request.Form collection.
There must be a way to use this or something similar.

I'll keep playing with it, but if anyone has got a more efficient and
developer-friendly solution, please let me know.

Many thanks,

Landers
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top