TextBox in Master Page

  • Thread starter Thread starter David C
  • Start date Start date
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
 
Yes. I forgot to mention that it only goes away when I postback to a
different content page. Thanks.

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).
 
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
 
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).
 
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.
 
Back
Top