两个文本框,txb1 和 txb2;
一个按钮,btn;从btn单击事件中,将 txb1.Text 的值赋给Session;从Page_Load事件中,可以将 Session 的值赋给 txb2.Text,而不能赋给 txb1.Text;一旦在Page_Load事件中将 Session 的值赋给 txb1.Text,就会导致 Session清空,并且 再赋给 txb2.Text 都不可以。请问这是怎么回事,如何解决?Visual Studio 2005
一个按钮,btn;从btn单击事件中,将 txb1.Text 的值赋给Session;从Page_Load事件中,可以将 Session 的值赋给 txb2.Text,而不能赋给 txb1.Text;一旦在Page_Load事件中将 Session 的值赋给 txb1.Text,就会导致 Session清空,并且 再赋给 txb2.Text 都不可以。请问这是怎么回事,如何解决?Visual Studio 2005
执行顺序的问题,Page_Load时你的Session 本来就是空的
同意,已进入就执行Page_Load事件,Session 此时无值 传给txb2.Text,
提交成功后,使用防后退功能,跳到jump页,然后由jump页再跳回来,需要保存数据到Session。
1、单击btn按钮,提交数据;
2、将txb1.Text的值取出,放入Session;
3、跳转到“提交成功,请稍候”页面,防后退功能。
4、将刚才Session值再给txb1.Text,因为这个文本框中的内容需要重复利用,我不想让使用者重新输入。
1、单击btn按钮,提交数据;
2、将txb1.Text的值取出,放入Session;
3、跳转到“提交成功,请稍候”页面,防后退功能。
4、由跳转页再跳回本页面。
5、将刚才Session值再给txb1.Text,因为这个文本框中的内容需要重复利用,我不想让使用者重新输入。
“页面1”提交成功→跳到“防后退页”→由“防后退页”跳回“页面1”需要:将“页面1”txb1.Text的数据通过跳转,依然还在txb1.Text中。
Session["userLogin"] = txb1.Text ;
Response.Redirect("jump.aspx");private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
if(Session["userLogin"]==null)
{
txb1.Text = Session["userLogin"].ToString();
}
}
}
Session["userLogin"] = txb1.Text ;
Response.Redirect("jump.aspx");private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
if(Session["userLogin"]!=null)
{
txb1.Text = Session["userLogin"].ToString();
}
}
}
都等于null了还赋值给txb1.text
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if (Session["TextBox1"] != null)
{
TextBox1.Text = Session["TextBox1"].ToString();
}
}
} protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != string.Empty)
{
Session["TextBox1"] = TextBox1.Text;
Response.Redirect("~/Web/AutoGridView.aspx?TextBox1="
+ Session["TextBox1"].ToString());
}
}
{
Response.Redirect("~/Web/ButtonAndSession.aspx");
}
第一个页面的传值只是为了验证看看是否像你说的Session值丢了。
{
protected void Page_Load(object sender, EventArgs e)
{
txbY.Text = Convert.ToString(Session["Name"]);
} protected void btn_Click(object sender, EventArgs e)
{
Session["Name"] = txbY.Text.Trim(); Session["URL"] = "Default.aspx";
Response.Redirect("UnBack.aspx");
}
跳转页: private void UnBack() // 防后退函数,强制不缓存页面。
{
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
Response.Expires = 0;
Response.CacheControl = "no-cache";
} protected void Page_Load(object sender, EventArgs e)
{
UnBack(); // 防后退,放在 page_load 里面。 string url = "<meta http-equiv=\"refresh\" content=\"1;url=" + Convert.ToString(Session["URL"]) + "\">";
Response.Write(url);
}
将Session赋给自己,怎么试都不成功;
是赋给另一个TextBox就可以。
Response.Write(url);
在调回Default页时 txbY.Text = Convert.ToString(Session["Name"]);
这设个断点看看,取值是多少,在改成赋值另外那个,看看你能赋值上的那个textbox 取值session的值是多少
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txbY.Text = Convert.ToString(Session["Name"]);
}
}