在带有会话变量的新窗口中打开表单 [英] Open form in new window with session variables

查看:62
本文介绍了在带有会话变量的新窗口中打开表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个表格,说:main.aspx

我上面有一个按钮,在按钮的单击事件上,我正在设置会话变量的值(例如:

Hi,

I have a form, say: main.aspx

I have a button on it, on click event of button, I am setting the value of a session variable (say:

Session["var"]="Value";

)

现在,在click事件上,我想在新窗口中打开表单(details.aspx),并在此页面上获取该Session变量值.


请帮忙吗?

)

Now on the click event, I want to open the form (details.aspx) in new window and get that Session variable value on this page.


Please help?

推荐答案

您应该可以使用HttpContext访问

You should be able to access using HttpContext

HttpContext.Current.Session["var"]



根据存储在会话变量中的数据类型,您需要进行类型转换.



Depending on the type of data you are storing in the session variable, you need to type cast it.


Session["var"]您可以直接获取session的值
Session["var"] you can get directly value of session
var r=Session["var"];


按钮单击事件

您已经设置了会话变量,如
Under Button Click event

You have Set Session Variable like
protected void Button1_Click(object sender, EventArgs e)
  { 
Session["var"]="Value";
Response.Redirect("details.aspx");
}


在details.aspx
在Pageload下,您可以像
那样获得会话


In details.aspx
Under Pageload you can get the session like

protected void Page_Load(object sender, EventArgs e)
   {
string str=session["var"].tostring()//here the key name should be same as prevoius session key name
   }


希望对您有帮助


Hope it will help you


这篇关于在带有会话变量的新窗口中打开表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆