【问题标题】:Maintain State of Previous Page After Clicking LinkButton单击链接按钮后保持上一页的状态
【发布时间】:2014-01-08 17:50:31
【问题描述】:

在链接中

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;
    }

在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"] : "";
   }

当我点击链接按钮时保持上一页的状态 我在网络表单上有两个网络表单,当我点击链接按钮时,我认为它会转到下一页,如果我在返回主页时完成,我会在主页中丢失数据,我尝试了会话但没有工作。

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

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

【问题讨论】:

  • 您是指视图状态还是会话?您的代码示例使用 Session,但您的描述谈论的是视图状态。
  • 恐怕您对问题的描述不清楚 - “contross”、“如果我在返回主页时完成了”等。我意识到英语可能不是您的第一语言,但会不会可以编辑您的答案并明确说明您的问题是什么?

标签: c# asp.net webforms


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-16
    • 2019-10-04
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 2019-05-01
    相关资源
    最近更新 更多