单击LinkBut​​ton后维护上一页的状态

时间:2014-01-08 17:50:32

标签: c# asp.net webforms

在linkbtn中

protected void lnkBtnSun_Click(object sender, EventArgs e)
    {
        Session["employeeName"] = txt_EmpName.Text;
        Session["Projectstaus"] = ddownList.SelectedValue;
        Session["Startdate"] = txt_StartDate.Text;
        Session["EndDate"] = txt_EndDate.Text;
        Session["lblsun"] = lbl_sun.Text;
        Session["lblmon"] = lbl_Mon.Text;
    }

in timesheet.aspx

    protected void Page_Load(object sender, EventArgs e)
   {
    string employeeName = (Session["employeeName"] != null) ? Session["employeeName"] : "";//cursor moves from textbox dropdown data is  disappering
    string projectStatus = (Session["Projextstaus"] != null) ? Session["Projextstaus"] : "";//maintains value when retun back from another webform
    string startDate = (Session["Startdate"] != null) ? Session["Startdate"] : "";
    string endDate = (Session["EndDate"] != null) ? Session["EndDate"] : "";//String was not recognized as a valid DateTime.
    string lblsun = (Session["lblsun"] != null) ? Session["lblsun"] : "";
    string lblmon = (Session["lblmon"] != null) ? Session["lblmon"] : "";
   }

点击链接按钮时保持上一页的状态 我在webform上有两个webforms我控制当我点击linkbutton它进入nextpage如果我完成了当retunrsn到主页我在主页中丢失数据时,我尝试了会话但没有工作。

txt_EmpName.Text = (Session["employeeName"] != null) ? Session["employeeName"].ToString() : "";

ddownList.SelectedValue = (Session["Projectstaus"] != null) ? Session["Projectstaus"].ToString() : "";

1 个答案:

答案 0 :(得分:0)

会话是这些场景中的典型解决方案。您是否将这些属性写入Session对象?否则,它们将始终为null,您将看到您正在描述的行为。