How to retreive Local Storage Key value

Posted on 2016-09-13
Last Modified: 2016-09-15
I am trying to retrieve the Local Storage Value from a browser.  The value is stored in the browser.

   <asp:HiddenField ID="hdnUserName" runat="server" />

     <asp:HiddenField ID="HiddenField1" runat="server" />


        function load() {
            hdnUserName = window.localStorage.getItem("PortalLoginApp.userName");                    

        window.onload = load;

Open in new window

Once I obtain the localStorage value I will need to access this value form code behind in
Question by:Member_2_7964962
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 82

Accepted Solution

leakim971 earned 500 total points
ID: 41797167
Please not you gonna be able to get this value server side ONLY after posting your page, not before open it or when open.
You must SUBMIT the page to server so the server can read both values of the hidden fields
        function load() {
            var userName = window.localStorage.getItem("PortalLoginApp.userName");                    
            document.getElementByid("<%= hdnUserName.ClientID %>").value = userName;
            var HiddenField1 = window.localStorage.getItem("PortalLoginApp.userName");                    
            document.getElementByid("<%= HiddenField1.ClientID %>").value = HiddenField1;
        window.onload = load;

Open in new window


Author Comment

ID: 41797203
Thank you, I will give this code a try and let you know.

Author Comment

ID: 41797794
I have a question.  in the browser window for the cookie there is a Name and a Value column.  Should I place the word Value in place of PortalLoginApp below like. var userName = window.localStorage.getItem("Value.userName");

var userName = window.localStorage.getItem("PortalLoginApp.userName");

Author Closing Comment

ID: 41799693
Your suggestions worked.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Video Tutorial help 2 39
MS Outlook auto update conflicts 5 28
setInterval() calls function twice in one interval 2 36
Target.Address conflict in Excel VBA 3 22
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question