473,387 Members | 1,882 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,387 software developers and data experts.

ViewState, Dynamic UserControls, and the Back Button

My web application dynamically creates a UserControl and saves it to a
Session variable called LastControl. When a postback occurs, I simply
load the LastControl and everything works great.

The problem occurs when the user hits the Back button. Then the
"LastControl" might be a different User Control and so when I reload
it, it causes instance errors since the user control it is expecting
is no longer in a Session variable.

Some solutions I have thought about are:

1. Creating a Session variable for each User Control and keeping it in
memory. I am afraid, though, that this could tax the web server's
memory, and this just seems like a kludgy solution.

2. Figure out a way to save the User Control and put it in the page's
ViewState. This would be ideal because then I would simply load the
dynamic control from the current page's view state and there would
never be an issue with the back button and no memory would be taken up
on the server.
Has anyone had success storing a User Control in a page's view state?
Nov 17 '05 #1
1 3639
My preferred solution would be to create the contorl every time you need it.

If that is too expensive, is the control different for each user? If not,
maybe you can use the Cache object instead of session. This way, you only
keep one copy and can better afford to keep older data around.

Jeff

"John Hamm" <jo**@snapjax.com> wrote in message
news:95**************************@posting.google.c om...
My web application dynamically creates a UserControl and saves it to a
Session variable called LastControl. When a postback occurs, I simply
load the LastControl and everything works great.

The problem occurs when the user hits the Back button. Then the
"LastControl" might be a different User Control and so when I reload
it, it causes instance errors since the user control it is expecting
is no longer in a Session variable.

Some solutions I have thought about are:

1. Creating a Session variable for each User Control and keeping it in
memory. I am afraid, though, that this could tax the web server's
memory, and this just seems like a kludgy solution.

2. Figure out a way to save the User Control and put it in the page's
ViewState. This would be ideal because then I would simply load the
dynamic control from the current page's view state and there would
never be an issue with the back button and no memory would be taken up
on the server.
Has anyone had success storing a User Control in a page's view state?

Nov 17 '05 #2

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

Similar topics

0
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
7
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
11
by: Nad | last post by:
Hello, I have a page with two link buttons. When I click on the first one I call server.execute("target.aspx") to view target.aspx on the original page. Then I click on the second link button...
1
by: Diffident | last post by:
Hello All, I am trying to add dynamic controls onto my page and here is how I am doing that. I have a page which has a button called as "AddMoreControls" and in this button's event handler I...
1
by: Gummy | last post by:
Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation = (ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");
0
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.