How get javascript session values in code behind into asp.net [Resolved]

Posted by Cpatil1000 under ASP.NET on 4/22/2016 | Points: 10 | Views : 610 | Status : [Member] | Replies : 1
Hi,

I am trying following javascript coding. Now I wan this session
value in cs. How do it.

<script type="text/javascript">
function SetUserName()
{
var userName = "Shekhar Shete";
'<%Session["UserName"] = "' + userName + '"; %>';
}
</script>




Responses

Posted by: Sheonarayan on: 4/23/2016 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
This is not the right approach. You should do following.

1. Store your session into JavaScript variable.
2. Set that variable value to HTML form hidden element.
3. When the form is submitted, access it using Request.Form["hiddenElementName"] .
4. If you do not have form, put this as a querystring to the url to redirect and access it using Request.QueryString["queryStringName,"] .

Hope this will help.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response