?
Solved

How to retreive Local Storage Key value

Posted on 2016-09-13
4
Medium Priority
?
93 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
[X]
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
4 Comments
 
LVL 82

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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