Solved

How to retreive Local Storage Key value

Posted on 2016-09-13
4
41 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now