locked
Retrieve Session variable from global.asax RRS feed

  • Question

  • Hi guys,

    I've declared a session variable in the global.asax page under the Session Start event like this:

    Session["myItem"] = "put URL here";

    How would I be able to call/reference this item in an .aspx page? More specifically, I want to put a hyperlink in the AccessDenied.aspx page using the myItem for its value (the "put URL here" part).

    Here's what I have in the AccessDenied.aspx page for the hyperlink:

       <asp:HyperLink id="GoToURL" NavigateUrl="put the value of myItem here somehow" Text="Go to URL"
                CssClass="ms-descriptiontext" runat="server"/> 
    Wednesday, July 27, 2011 12:56 PM

Answers

  • Try below code. It will work . I have tried @ my end

     

     <script language='javascript'>

            function MyDoc() {

                var oURL = '<%= Session["myItem"].ToString()%>'

                alert(oURL); 

            }

        </script>

       <asp:HyperLink id="GoToURL" onclick="javascript:MyDoc(); return false;" Text="Go to URL"

                CssClass="ms-descriptiontext" runat="server"/> 

     


    Rahul Sharma -------------------------- Coding is all about passion !!!!!!
    • Marked as answer by petabread1214 Wednesday, July 27, 2011 2:41 PM
    Wednesday, July 27, 2011 2:06 PM

All replies

  • Try below code. It will work . I have tried @ my end

     

     <script language='javascript'>

            function MyDoc() {

                var oURL = '<%= Session["myItem"].ToString()%>'

                alert(oURL); 

            }

        </script>

       <asp:HyperLink id="GoToURL" onclick="javascript:MyDoc(); return false;" Text="Go to URL"

                CssClass="ms-descriptiontext" runat="server"/> 

     


    Rahul Sharma -------------------------- Coding is all about passion !!!!!!
    • Marked as answer by petabread1214 Wednesday, July 27, 2011 2:41 PM
    Wednesday, July 27, 2011 2:06 PM
  • Thank you so much Rahul, you just saved a lot of my time researching :)

    -Peter

    Wednesday, July 27, 2011 2:41 PM