[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to retreive Local Storage Key value

Posted on 2016-09-13
4
Medium Priority
?
101 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 83

Accepted Solution

by:
leakim971 earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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…
Suggested Courses

834 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