Correct me if I am Wrong, As per my knowledge we cannot access the session object from the Client side. So how is it possible to fill the data of session from the client side.
It's not possible to fill session from Client side...But i done a lot many R & D and finally come to know that it is possible to send request to server side with help of AJAX and we can do that...
But i need to confirm , is it possible to do with help of AJAX ?
Anal Patel
Member
3 Points
11 Posts
I want to fill data in Session via Java script
Mar 31, 2012 07:49 AM|LINK
Hello,
I need to fill session value with help of Java script..
The problem is , my Java script function return false at the end of function.and just before that i want to fill session.
I tried a lot many R & D but not succedd.
Or is it possible to fill session with help of AJAX ?
Please please please help me......
ceenu4u
Member
98 Points
29 Posts
Re: I want to fill data in Session via Java script
Mar 31, 2012 08:03 AM|LINK
Correct me if I am Wrong, As per my knowledge we cannot access the session object from the Client side. So how is it possible to fill the data of session from the client side.
Anal Patel
Member
3 Points
11 Posts
Re: I want to fill data in Session via Java script
Mar 31, 2012 08:40 AM|LINK
You are right...
It's not possible to fill session from Client side...But i done a lot many R & D and finally come to know that it is possible to send request to server side with help of AJAX and we can do that...
But i need to confirm , is it possible to do with help of AJAX ?
Ruchira
All-Star
43040 Points
7032 Posts
MVP
Re: I want to fill data in Session via Java script
Mar 31, 2012 12:18 PM|LINK
Hello,
Yes you can set sessions in a web service. Do a ajax call to a webservice and set the session in that webservice.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.ashish-1983
Contributor
4879 Points
1257 Posts
Re: I want to fill data in Session via Java script
Mar 31, 2012 01:55 PM|LINK
<script type="text/javascript"> <!-- function setSessionVariable(valueToSetTo) { __doPostBack('SetSessionVariable', valueToSetTo); } // --> </script> private void Page_Load(object sender, System.EventArgs e) { // Insure that the __doPostBack() JavaScript method is created... this.GetPostBackEventReference(this, string.Empty); if ( this.IsPostBack ) { string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"]; string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"]; if ( eventTarget == "SetSessionVariable" ) { Session["someSessionKey"] = eventArgument; } } }Gridview
Jquery
Asp.net
Fun !
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: I want to fill data in Session via Java script
Apr 01, 2012 02:49 AM|LINK
Hi,
You can also consider ASP.NET Client Call Backs!
http://msdn.microsoft.com/en-us/library/ms178208.aspx
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
Anal Patel
Member
3 Points
11 Posts
Re: I want to fill data in Session via Java script
Apr 02, 2012 06:15 AM|LINK
Guys,
Thank you very much for your Quick Response.
The problem with my code is , I can't postback my page.
Anal Patel
Member
3 Points
11 Posts
Re: I want to fill data in Session via Java script
Apr 02, 2012 06:16 AM|LINK
Hi Ruchira,
Can you please provide me Demo Code ?
Anal Patel
Member
3 Points
11 Posts
Re: I want to fill data in Session via Java script
Apr 02, 2012 06:20 AM|LINK
My code is soething like....
<script type="text/javascript" language="javascript">
function Test (obj,obj)
{
--
--
------
**** I want to fill session at this stage ****
window.open("Default.aspx" + DefaultstrRequestParam ');
return false;
}
</script>
** Note: The problem with my code is i can't postback my page...
Ruchira
All-Star
43040 Points
7032 Posts
MVP
Re: I want to fill data in Session via Java script
Apr 02, 2012 12:48 PM|LINK
Hi,
Your web service should be something like below
[WebMethod(EnableSession = true)] public void Sessioncall(sessionValue) { Session["Test"] = "Set session value here"; }Then send an AJAX call to this webservice from your javascript code. Please google/bing for how to send an AJAX request using jQuery/Javascripts.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.