Click here to Skip to main content
15,885,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi Friends
I want to set session values in java script and pass label values in code behind how to possible thanks to advance
Posted
Updated 26-Dec-13 18:33pm
v2

create a code behind method like below
C#
[WebMethod]
   public static string SetSession(string sessionval)
   {
     Session["mysession"]=sessionval;
   }


call it using ajax

JavaScript
<script>
function  SetValue(myval)
{
   $.ajax({
   url:"YourPageName.aspx/SetSession",
  Type:'POST',
  data:{sessionval:myval},
  success:fucntion(response){}
});
}

<script></script></script>


Hope this helps!!!
 
Share this answer
 
In order to set a value from the client back to the server requires a Page Submit or an ajax call ( Partial ). Already , as Zubair suggested in the first solution.
 
Share this answer
 
Hey

You can set Session variables using Javascript like this

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


And you can retrieve the values like this

XML
<script type="text/javascript">
    function GetUserName()
    {

        var username = '<%= Session["UserName"] %>';
        alert(username );
    }
</script>



What exactly do you mean by passing label values. You can set the properties of label from the code behind simply like

C#
lblUserName.Text="Shahid Bhat" // Where lblUserName is the ID of the label.
 
Share this answer
 
Refer:-session in javascript in asp.net[^]
Check Solution 2 and Solution 3.
This may help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900