Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • BJ Patel 84 posts 210 karma points
    Oct 13, 2015 @ 20:27
    BJ Patel
    0

    Set Session value using Javascript and retrieving the same using razor umbraco

    I have written following code let say in Page 1

    <script type="text/javascript">
    
            function setSessionValue()
            {
                var selectedCarNoideId = "1026";                                
                <%Session["BannerNoideID"] = "'+ selectedCarNoideId +'";%>              
                alert('<%=Session["BannerNoideID"]%>');         
            }
    
    </script>
    

    And now retrieving session value on other page (Scripting File .chtml) using following code.

    <h2>Session-:@Session["BannerNoideID"]  </h2>;
    

    In the Page 1 alert PopUp displays "1026" as session value

    But In Page 2

    tag display following value as a output of session .

    "Session-:'+ selectedCarNoideId +'"

    Am I missing any thing ?

  • Steve Morgan 1350 posts 4460 karma points c-trib
    Oct 14, 2015 @ 07:31
    Steve Morgan
    0

    HI,

    You can't set session side session variables from Javascript. I notice some of the code you've posted is from this link.. http://stackoverflow.com/questions/15519454/how-can-i-access-session-variables-and-set-them-in-javascript

    Read the comments further down. If you want to do this you need to create an AJAX POST to update this on the server though if the selection of a car is a major event it might just be easier to POST this.

    Steve

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" button below.

    Continue discussion

Please Sign in or register to post replies