The only way that you would be able to do this would be through AJAX Requests, assuming your are referring to the actual Session (that you can store values in) within ASP.NET as Javascript alone cannot access it (client-side vs server-side).
I suppose you could define two WebMethods within your BusDetails.aspx page and then make AJAX Requests to either set or retrieve the value from the Session :
If you have any other questions about my reply, please let me know freely.
Best Regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I'm a bit confused as to what you are currently attempting to do. Could you consider posting a larger section of code so that we could see exactly what you are doing?
If you are checking the user's credentials (username and password) within your Login.aspx page, I would recommend just setting the Session value within the same server-side code in your Login.aspx page.
Member
54 Points
518 Posts
How to send and check session using jquery
Sep 19, 2014 07:53 AM|klbaiju|LINK
Hi,
in my application ,i want to send session using jquery and also check session using jqiuery
for example
var uname=$('#txtuname').val();
$.ajax({
type: "POST",
url: "WebService.asmx/Checklogin",
data: "{'uname':'" + uname + "','password':'" + password + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
//alert(msg.d);
if (msg.d == "Success") {
location.href = "Busdetails.aspx";
//set session here
Session["uname"]=uname;
}
}
});
*********************************
in busdetails.aspx i want to check session
how it is possible.
Regards
Baiju
All-Star
194511 Points
28081 Posts
Moderator
Re: How to send and check session using jquery
Sep 19, 2014 07:57 AM|Mikesdotnetting|LINK
You can't set session values in Javascript. What problem are you trying to solve?
Member
54 Points
518 Posts
Re: How to send and check session using jquery
Sep 19, 2014 08:05 AM|klbaiju|LINK
my requirement is if msg.d="Success"
i want to set and send session value to another page in any way using jquery or serverside
if (msg.d == "Success") {
location.href = "Busdetails.aspx";
//set session here
Session["uname"]=uname;
}
All-Star
194511 Points
28081 Posts
Moderator
Re: How to send and check session using jquery
Sep 19, 2014 08:12 AM|Mikesdotnetting|LINK
You can add the user name to the url and use it to set the session value in Page_Load:
Then in BusDetails.aspx Page_Load:
All-Star
114593 Points
18503 Posts
MVP
Re: How to send and check session using jquery
Sep 19, 2014 08:19 AM|Rion Williams|LINK
The only way that you would be able to do this would be through AJAX Requests, assuming your are referring to the actual Session (that you can store values in) within ASP.NET as Javascript alone cannot access it (client-side vs server-side).
I suppose you could define two WebMethods within your BusDetails.aspx page and then make AJAX Requests to either set or retrieve the value from the Session :
This way if you needed to retrieve a Session key through AJAX, you could use :
or if you needed to set one :
Member
54 Points
518 Posts
Re: How to send and check session using jquery
Sep 19, 2014 08:34 AM|klbaiju|LINK
Hi Mikes ur code is working.but some security issue
it will display in address bar like
http://localhost:50750/Lekshmi/Busdetails.aspx?uname=baiju.
after closing and paste this address bar it will directly go to Busdetails.aspx.
any solution for this
All-Star
194511 Points
28081 Posts
Moderator
Re: How to send and check session using jquery
Sep 19, 2014 08:57 AM|Mikesdotnetting|LINK
The solution is to move your webmethod out of the asmx file and into your aspx file as illustrated by Rion.
Member
54 Points
518 Posts
Re: How to send and check session using jquery
Sep 19, 2014 09:05 AM|klbaiju|LINK
Hi Rion Busdetails is my target page,
iam checking uname and password in login.aspx like this.
success: function (msg) {
/
if (msg.d == "Success") {
location.href = "Busdetails.aspx";
}
where should i write setsession value. i think it should be in login.aspx.
still iam confused
All-Star
45489 Points
7008 Posts
Microsoft
Re: How to send and check session using jquery
Sep 26, 2014 02:48 AM|Zhi Lv - MSFT|LINK
Hi klbaiju,
From my point of view, you could set session value in the web service. For more details, you could refer to the following code:
Code in Page (Login Page)
Code in Page()
Code in Page (Default page)
If you have any other questions about my reply, please let me know freely.
Best Regards,
Dillion
All-Star
114593 Points
18503 Posts
MVP
Re: How to send and check session using jquery
Sep 26, 2014 10:11 AM|Rion Williams|LINK
I'm a bit confused as to what you are currently attempting to do. Could you consider posting a larger section of code so that we could see exactly what you are doing?
If you are checking the user's credentials (username and password) within your Login.aspx page, I would recommend just setting the Session value within the same server-side code in your Login.aspx page.