TextBox in Master Page

D

David C

I have a search TextBox in a Master Page that I am using in a
SelectParameter of a GridView. After typing text in it and doing a postback
the text disappears. How can I retain the text in the TextBox located in the
Master Page? Thanks.

David
 
D

David C

Yes. I forgot to mention that it only goes away when I postback to a
different content page. Thanks.

David
 
S

Stan

Yes.  I forgot to mention that it only goes away when I postback to a
different content page.  Thanks.

That is to be expected because the Master Page is only a template.
Going from one content page to another is the same as requesting an
entirely different page. Viewstate is not preserved between page
requests to different pages (it can't be because it's structure and
content won't be the same).

Use Session. That's what its for. Also any controls in Gridview must
trigger a postback to the original page first so that the TextBox
content can be stored in Session. Redirection or transfer to another
page can then proceed but the code for restoring the textbox in the
Master page will have to be executed at the destination page (code can
be placed in the MasterPage Page_Load event).
 
T

ThatsIT.net.au

David C said:
Yes. I forgot to mention that it only goes away when I postback to a
different content page. Thanks.

then you need to handle it manualy, master pages are not like frames, you
need to think of them as different pages
 
D

David C

Thank you both. I will either use session or pass a querystring.

David
Yes. I forgot to mention that it only goes away when I postback to a
different content page. Thanks.

That is to be expected because the Master Page is only a template.
Going from one content page to another is the same as requesting an
entirely different page. Viewstate is not preserved between page
requests to different pages (it can't be because it's structure and
content won't be the same).

Use Session. That's what its for. Also any controls in Gridview must
trigger a postback to the original page first so that the TextBox
content can be stored in Session. Redirection or transfer to another
page can then proceed but the code for restoring the textbox in the
Master page will have to be executed at the destination page (code can
be placed in the MasterPage Page_Load event).
 
H

Hillbilly

Wait a minute. You can also use ViewState just as easily:

ViewState["GridViewTextBox"] = "whatever";

Its a judgement call but don't go off using the Session or a QueryString
until you consider all the several most useful options. For example you
could also use a hidden form field to pass the data around. Very simple.

Managing state is always a matter of context.
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top