关于session传值问题,谢谢
以下是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection lee = new SqlConnection("Data Source=.;Initial Catalog=shop;Integrated Security=True");
lee.Open();
string StuSQL1;
StuSQL1 = "select top 10 Title from Information order by date desc";
SqlCommand StuIns1 = new SqlCommand(StuSQL1, lee);
SqlDataAdapter da = new SqlDataAdapter(StuIns1);
DataTable dt = new DataTable();
da.Fill(dt);
LinkButton1.Text = dt.Rows[0][0].ToString();
lee.close();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Session["Title"] = LinkButton2.Text;
}
接受页面代码:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Title"] != null)
{
Label1.Text = Session["Title"].ToString();
}
请问我这样写为什么传不过去,
而且如果将Session["Title"] = LinkButton2.Text;
放在page_load那段代码中就可以传值
谢谢各位
------解决方案--------------------protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>location.href='To.aspx?Text=" +LinkButton2.Text+ "'</script>");
}
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["Text"] != null)
{
Label1.Text = Request.QueryString["Text"].ToString();
}
------解决方案--------------------1.直接跳转页面的话,你用页面传值更好
"content.aspx?title=abc";
2.LinkButton1.PostBackUrl 第一次点击就是赋值..当然要第二次才能跳转了
LinkButton1.PostBackUrl = "~/content.aspx";
放在Page_Load中...
------解决方案--------------------
protected void LinkButton2_Click(object sender, EventArgs e)
{
Session["Title"] = LinkButton2.Text;
Response.Redirect("content.aspx");
}