How to retreive Local Storage Key value

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
Member_2_7964962Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
leakim971Connect With a Mentor PluritechnicianCommented:
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
 
Member_2_7964962Author Commented:
Thank you, I will give this code a try and let you know.
0
 
Member_2_7964962Author Commented:
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
 
Member_2_7964962Author Commented:
Your suggestions worked.
0
All Courses

From novice to tech pro — start learning today.