Remembering textbox values on postback

L

Louisa99

Hello. ive just read some posts on the age old issue of losing dynamic
control values on postback. Most people say recreate the controls on the
onInit, but i just dont think this serves my purpose. if i could explain: i
have a list of reports in a datalist. a user clicks a report link. it goes
off to reporting services, fetches the parameters for this report and
displays x number of textboxes (and labels) for those parameters (hence it
must be dynamic). i do this by adding controls to a placeholder. (they are
user controls containing labels and textboxes, validation controls etc, to
control the look and feel but for simplicity we can just say textboxes). the
user enters report parameters. hits 'run report' and i need to take those
parameters and send them to the report render method. when i am about to get
the parameters, i have to go back to those controls to get the values. but
BANG placeholder.Controls.Count = 0 . Yes my controls have all gone :eek:( its
not that i particularly want them to stay displayed : i can probably manage
to convince the client that a refreshed screen will do (after all they have
their report flashed up in another window). but losing the text box value to
send to the parameter, and appropriate parameter name (i get that from the
label), that basically means i dont know what parameters the user wants to
send to the report. can anyone think of a way round this? Can I use
viewstate? or another 'alternative' someone knows about? my code is within
an ajax update panel too if that makes a difference. (i thought this wouldnt
happen when i was writing it as i thought its an ajax call back not a
postback. but alas i was wrong. sorry for long post and thanks in advance.
louise.
 
B

bruce barker

update panels are a postback. the control values are sent to the server,
the page processed, then just the update panels html is sent back.

when you render the page, store the reportid in viewstate. in oninit
(and a postback), get the value and call the reporting service to get
the parameters.

your other option is to store the list of parameters in viestate


-- bruce (sqlwork.com)
 
L

Louisa99

bruce barker said:
update panels are a postback. the control values are sent to the server,
the page processed, then just the update panels html is sent back.

when you render the page, store the reportid in viewstate. in oninit
(and a postback), get the value and call the reporting service to get
the parameters.

I will still lose the values that the user gave them parameters in teh text
box though. I have to store a key/value pair somehow then
(parametername/value). i'll read up how to do that in viewstate. thanks.
 
Joined
May 5, 2009
Messages
1
Reaction score
0
Hi,

I'm trying to do something similar and have a potential quick (but not particularly nice) fix that will hopefully tide you over until something better appears. Similarly if someone knows a better approach than I'm using for a static object then please let me know.

I'm using the following for obtaining a vaule for a static object:

string aliasId = Request.Form[MeasureAliasDropDownList.ClientID.Replace("_", "$")];

Providing it's not a 'too busy' page you could grab the client id from a debug, add a watch for Page.Request.Form.AllKeys and locate your control or alternatively build it up from the various containers. Then use the id string as follows:

string controlToFindClientIDString = "[Hard coded client id string]";

string valueFromControl = Request.Form[controlToFindClientIDString];

Hope this makes sense.
 

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,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top