在jquery.click设置ASP.NET会话() [英] Setting a ASP.NET Session in jquery.click()
问题描述
当用户选择我的网站上一个标签,我想保存它们是选项卡上,这样我可以在页面刷新后,回到那里给他们。我有这样的时刻(借口坏的编码自动取款机,我测试的概念):
When a user select a tab on my site, I would like to store which tab they are on so that I can send them back there after the page refreshes. I have this at the moment (excuse the bad coding atm, I am testing the concept):
$("#index_0_li").click(function() {
<%= Session["SelectedIndex"] = "0" %>
});
$("#index_1_li").click(function() {
<%= Session["SelectedIndex"] = "1" %>
});
var index = <%= Session["SelectedIndex"] %>;
问题是,因为&LT;%=%&GT;
不等待上点击,指数总是被设置为1。
The problem is, because <%= %>
doesn't wait for the on click, the index is always being set to 1.
有没有人对我怎么能做到什么,我试图做?任何想法
Does anyone have any ideas on how I can achieve what I am trying to do?
感谢。
推荐答案
只要使用客户端会话 - 又名曲奇
Just use client-side session - aka "cookies".
设置的cookie上的click事件,那么当你提交页面(或后退),此cookie将与HTTP请求发送,让您通过 Request.Cookies时阅读
。
Set the cookie on the click event, then when you submit the page (or "post back"), this cookie will be sent with the HTTP request, allowing you to read it via Request.Cookies
.
这篇关于在jquery.click设置ASP.NET会话()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!