Solved

How to retreive Local Storage Key value

Posted on 2016-09-13
4
53 Views
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" />

    

    <script>
        function load() {
            hdnUserName = window.localStorage.getItem("PortalLoginApp.userName");                    
            localStorage.getItem(localStorage.Key);
            }

        //}
        window.onload = load;
        </script>

Open in new window


Once I obtain the localStorage value I will need to access this value form code behind in asp.net
0
Comment
Question by:Member_2_7964962
  • 3
4 Comments
 
LVL 82

Accepted Solution

by:
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
    <script>
        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;
    </script>

Open in new window

0
 

Author Comment

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

Author Comment

by:Member_2_7964962
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");
0
 

Author Closing Comment

by:Member_2_7964962
ID: 41799693
Your suggestions worked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now