473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I save state?

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
Nov 27 '05 #1
4 3081
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/Dy...dControls.aspx
And this is an example where I used the first strategy above
http://www.societopia.net/Samples/Da...olsEvents.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"landers" wrote:
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

Nov 27 '05 #2
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

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:FE**********************************@microsof t.com...
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/Dy...dControls.aspx
And this is an example where I used the first strategy above
http://www.societopia.net/Samples/Da...olsEvents.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"landers" wrote:
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

Nov 27 '05 #3

You are welcome, Landers. I too certainly look forward to reading other
programmers approaches to this scenario.

Meanwhile here are 2 additional articles from MSDN to explain the necessity
of loading the controls upon page initialization:

http://msdn.microsoft.com/library/de...nlifecycle.asp

http://msdn.microsoft.com/library/de.../viewstate.asp

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"landers" wrote:
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

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:FE**********************************@microsof t.com...
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/Dy...dControls.aspx
And this is an example where I used the first strategy above
http://www.societopia.net/Samples/Da...olsEvents.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"landers" wrote:
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


Nov 27 '05 #4
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

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:C0**********************************@microsof t.com...

You are welcome, Landers. I too certainly look forward to reading other
programmers approaches to this scenario.

Meanwhile here are 2 additional articles from MSDN to explain the
necessity
of loading the controls upon page initialization:

http://msdn.microsoft.com/library/de...nlifecycle.asp

http://msdn.microsoft.com/library/de.../viewstate.asp

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"landers" wrote:
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

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:FE**********************************@microsof t.com...
> 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/Dy...dControls.aspx
> And this is an example where I used the first strategy above
> http://www.societopia.net/Samples/Da...olsEvents.aspx
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "landers" wrote:
>
>> 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
>>
>>
>>


Nov 27 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
2
by: FlashMerlot | last post by:
We have an ASPX (C#) webform which hosts dropdownlists, textboxes, grids, checkboxes, etc. The users want to: #1 - "FREEZE" the entire webpage contents (and state) #2 - move IE browser to...
1
by: rob | last post by:
I built a combo box that contains names of people. A user can chooses a person from the combo box, the next couple of the text boxes will show the corresponding address of that person. I used...
7
by: John J. Hughes II | last post by:
I need to save a DWORD to the sql server, the below posts an error, any suggestions on what I am doing wrong. I have the column in the sql server defined as an int since unsigned int is not valid....
1
by: Adrijan Josic | last post by:
I have a bunch of user controls that contain TextBoxes, Repeaters and so on. Some of the user controls even contain other user controls. The user controls also usually have some of their...
1
by: Irene | last post by:
Hello all! I'm creating a web site in ASP.NET (VB.NET). One of the requirements was to allow users to create orders going through several steps. A must have is to have an option to save the work...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
7
by: newscorrespondent | last post by:
I want to save the state of a splitcontainer when an application ends. I also save the form state. The SplitContainer does not seem to have a well defined place to put intiialization and...
1
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
14
by: squrel | last post by:
Hello everyone, I m using some button using toolbar such as Add,Save,View,.... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.