RE: State problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.
.



Relevant Pages

  • Re: Re: Book on Pre-MATH for cryptography and cryptanalysis. Reply
    ... He can deposit better controls off the responsible ... marvellous execution, whilst Sam nevertheless devotes them too. ...
    (sci.crypt)
  • Re: Doall c58 bandsaw wiring help
    ... Sam, ... well as associated controls to cycle in fully automatic mode. ... I had a PLC controlled cold saw ... Gary H. Lucas ...
    (alt.machines.cnc)
  • Re: Page_PreInit
    ... If page has controls then first Init of all those controls is called before ... Init of the page is called. ... PreInit is the one that called first. ... will be overridden when controls read it's own value from PostBack stream.. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: State problem
    ... You should be creating dynamic controls in the PreInit page event. ... "I am Sam" wrote: ... the actual control into viewstate I'm all eyes. ... someone tell me how to persist the dynamic control beyond postback including ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to display RTF text stored in database as IMAGE to a asp.net page
    ... sourceforge has open source code. ... Sam wrote: ... it in a RichTextBox control on a windows form. ... see any controls that will allow me to do this. ...
    (microsoft.public.dotnet.framework.aspnet)