前台脚本中获取Session值的问题,急求! 本帖最后由 free1985 于 2012-10-31 09:48:43 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本人新手,请给予具体代码示例指导,代码片段、demo或博客链接,谢谢。本人邮箱:[email protected] namespace WebApplication1{ [AjaxNamespace("hehe")] public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1)); } [AjaxPro.AjaxMethod] public object GetDate() { return Session["name"]; } }}前台JS var da= hehe.GetDate().value;web.config要加句话<httpHandlers> <add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2" /> </httpHandlers>在在项目中添加ajaxpro.2.dll的引用 在cs中用[webmethod]标注获取session值的方法,前台用jquery的ajax获取,这样应该可以的 <%= Session["KEY"] %> 就可以了 何必用 AJAX js与cs之间的交互只能能过get,post来完成例如getSession.aspx?key=...Response.Write(Session[Request["key"]]);...<script>var test="kk";jQuery.get('getSession.aspx?key='+ test,'',function(data){...});</script> 可以使用cookie解决.后台写cookie的代码如下:Response.Cookies["ID" + i.ToString()].Value = "test" + i.ToString(); 前台读cookie的代码如下:var arr = document.cookie.match(new RegExp("(^| )"+szTemp+"=([^;]*)(;|$)")); if(arr != null) { document.getElementById("Label1").textContent = arr[2]; } http://topic.csdn.net/u/20101124/21/dc9f7a11-b4e1-4099-923c-895b2fb1d83d.html 在DAL层中, 如何从web.config中读取数据库的连接字符串? 请问如何在服务器端改文件名? 怎样在DropDownList加上OnClientClik属性? html radio button 的使用 datagrid获取当前行某列的值? 我在等啊 ~~~ 求两个整数相除,返回大小或等于结果的最小整数??? 怎么把Json数组中Unicode转换为汉字 瀑布流后台实现的问题 各位大虾能帮我写个用ajax实现页面异步刷新的例子吗? 如何点击一个button把服务器端的数据库备份到本地的电脑硬盘中? 问个文件上传的问题? 又遇到怪事,IE版本和Session的问题
{
[AjaxNamespace("hehe")]
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1)); }
[AjaxPro.AjaxMethod]
public object GetDate()
{
return Session["name"];
}
}}
前台JS
var da= hehe.GetDate().value;
web.config要加句话<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2" />
</httpHandlers>在在项目中添加ajaxpro.2.dll的引用
...
<script>
var test="kk";
jQuery.get('getSession.aspx?key='+ test,'',function(data){...});
</script>
后台写cookie的代码如下:
Response.Cookies["ID" + i.ToString()].Value = "test" + i.ToString(); 前台读cookie的代码如下:
var arr = document.cookie.match(new RegExp("(^| )"+szTemp+"=([^;]*)(;|$)"));
if(arr != null)
{
document.getElementById("Label1").textContent = arr[2];
}