最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to avoid Master Page hidden field value lost on new page load. - Stack Overflow

programmeradmin2浏览0评论

I have a hidden field on master page. I am setting its value on a child page through JavaScript. When I click link on this child page it redirects to another page. Now I want to get the hidden field value on this new child page. But the value is lost(obviously). How can I persist this value.

Anyone help thanks in advance.

I have a hidden field on master page. I am setting its value on a child page through JavaScript. When I click link on this child page it redirects to another page. Now I want to get the hidden field value on this new child page. But the value is lost(obviously). How can I persist this value.

Anyone help thanks in advance.

Share Improve this question edited Nov 21, 2011 at 12:43 anglimasS 1,3442 gold badges16 silver badges41 bronze badges asked Nov 21, 2011 at 12:39 Irfan TahirKheliIrfan TahirKheli 3,6621 gold badge25 silver badges36 bronze badges 1
  • 2 +1 good question / but can i suggest to set a session by ajax call instead of this scenario and use the session where ever you are , about ur hidden field i think the hidden field state is related to the page viewstate so every page have its own viewstate so the hiddenfield value will be flushed when ever you switch pages – Marwan Commented Nov 21, 2011 at 12:42
Add a ment  | 

8 Answers 8

Reset to default 2

You can pass the value in the query string like this:

http://YourUrl./YourPage.aspx?YourValue=foo

Alternatively, you can initiate an AJAX call that stores the value in the session and then retrieve the value on the page_load event of the next page.

You can add the value to the link when ever you change it.

Or you can use ajax to send the new value to the server after the change.

Your basic choices are to use javascript to either append it the link url as a querystring value or store it in a cookie.

visit these links might be it helps you

http://www.codeproject./Answers/219800/How-to-get-hidden-field-value-using-javascript-in-.aspx#answer3

How To: add dynamically HiddenField in masterpage base page

You mentioned that the page is redirect to another page, that means you must be using Response.Redirect or client side redirect. In this scenario you would not be to persist the hidden field value. To achieve this you might use a ajax call to save the value in a session variable and reload it on a appropriate master page event.

you can do that by handling the OnPageLoad event of your Master-page and assigning the value there too.

Kind of defeats the purpose of master pages eh? That was what the original intention was.

use viewstate in the masterpage it works perfectly for this type of scenario

public string NavigateUrl
{
 get
  {
    string text = (string) ViewState["NavigateUrl"];
    if (text != null)
       return text;
    else
       return string.Empty;
  }
  set
  {
    ViewState["NavigateUrl"] = value;
  }
}
发布评论

评论列表(0)

  1. 暂无评论