RE: State problem
- From: William Sullivan <WilliamSullivan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 1 Dec 2006 06:31:00 -0800
Solved.
I checked my page event list for some hints, and may have found something.
You should be creating dynamic controls in the PreInit page event. That
includes re-creating the controls so that when the viewstate is decoded the
controls can be filled with the data from the client. You may have to store
some data in the user's session state in order to re-create these controls in
the PreInit event.
Check out http://www.codeproject.com/useritems/lifecycle.asp
and
http://www.google.com/search?q=asp.net+%22dynamic+controls%22+preinit+viewstate
for more information.
http://msdn2.microsoft.com/en-us/ms178472.aspx contains an awesome list of
all page events and what they are commonly used for.
"I am Sam" wrote:
Actually, what I could do is loop through the database at page_load and.
determine the number of fields and instentiate the number of controls based
on the returned number of fields.
What do you think? Will that work?
"I am Sam" wrote:
Augh, I wish it were so simple. The number of controls is nControls. The
user depending on the environment uses an unknown number of dynamically
created controls at runtime so it is impossible to know which controls to
instantiate at page_load. If you have any other suggestions like stuffing
the actual control into viewstate I'm all eyes. Nevertheless, thank you for
your speedy reply.
"William Sullivan" wrote:
I encountered that problem before; rather than figuring out what was
happening (time constraints) I simply created all the controls I might need,
then dynamically made them visible or invisible, depending on what was
required.
"I am Sam" wrote:
I'm using some dynamically created textboxes to get user information.
The problem I am having is kind of complicated for me. The dynamic textbox
is found at the state in which it was created but is henceforth lost on
postback. Which means I lose the user input when an event is triggered. Can
someone tell me how to persist the dynamic control beyond postback including
the content inputed by the user. I have tried stuffing the control into
viewstate and failed to return the desired results.
For example I have tried:
TextBox tb=((TextBox)Subject1.FindControl("DyamicControlID"));
string tbcontent=tb.Text;
I am able to find this control successfully when it is in the event where it
is instanciated but is then lost after postback.
Please someone help me with this I am pulling my hair out trying to figure
out how to resolve this issue.
Please and thank you Sam I am.
- Follow-Ups:
- RE: State problem
- From: I am Sam
- RE: State problem
- Prev by Date: Multiple Projects on single web site
- Next by Date: Help Needed: Can't Successfully Perform Server-side Redirection
- Previous by thread: Multiple Projects on single web site
- Next by thread: RE: State problem
- Index(es):
Relevant Pages
|