views:

38

answers:

2

Hi, I have a problem regarding the maintaining of value when page was refresh.I assign a value into a hidden control using javascript below:

function displaytab(tabID) {
   var tabId = document.getElementById("ctl00_MainContent_tabId"); 
    switch (tabID) {
        case 1:
          tabId.value=1;
          break;
        case 2:
          tabId.value=2;

          break;
        case 3:
          tabId.value=3;

          break;
        default:
         tabId.value=0;

           break;     
     }

but when i refresh the page the value was ("") blank. Is there any way how to resolved this issue? or what is the best way to do this?

+1  A: 

You might consider putting the values you need to store across refreshes into the page anchor (the part of the URL following the # sign). You can access this in javascript via the location.hash member.

Amber
hi Amber, is there any way to get the value in server side?i tried this one for eg http://sample.com#1.All I want now is to get the value which is 1 using server side code.
The anchor/hash value is never seen by the server, so you'd need to submit it some other way (via an AJAX request or a form submission, or loading another page and passing it via a query paramter).
Amber
ok,thank you very much Amber, i think i have to use the location.hash that you've already suggested. then i have call the javascript function on onload event then pass the value as a parameter getting from location.hash. thank very much.
A: 

Ensure displayTab is not called until the DOM is ready.

A easy way would be calling your function in window.onload:

window.onload = function()
{
    displayTab(123);
};
ThiefMaster
i tried this one but the value still blank