Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I have locastorage value in one page, when open another page i want to pass that locastorage to hidden field when page get ready.

What I have tried:

When i try to pass , hidden field value empty in server side page load, i passed from client side, when i put alert msg , can get value from locastorage.

I think i passed value to hidden field before that control fully load in that page.
This i code

First Page - usernameN is textbox, on page submitt event i set value to localStorage

 <form id="form1" runat="server" onsubmit="myFunction()">
   
function myFunction() {
            localStorage.setItem("lsuser", $("#usernameN").val());
            
        }


On second page i use this code

$(document).ready(function () {
            var value = localStorage.getItem("lsuser");
    // alert(value);
    document.getElementById("lshduser").value = value;
        }
        )


But from server side page load lshduser is empty.
Any other method to pass value from client to server side page form one page to another page.

Note : except session variable in server side.

pls reply asap
Regards,
Aravind
Posted
Updated 24-Apr-19 11:16am
Comments
MadMyche 23-Apr-19 7:26am    
How is that value supposed to be getting to the server; is there a form/submit somewhere or an AJAX call?

1 solution

The hidden field is populated from Javascript. It won't have a value until the Javascript has run, which happens after the server-side code has executed.

That means your hidden field will be empty when you first load the page. When you post the page back to the server, the hidden field will be populated.

If you need the value when the page first loads, then you'll need to use an alternative. Other than session state, you can use cookies, the querystring, or a cross-page postback.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900