【问题标题】:Saving entire page's controls state in session在会话中保存整个页面的控件状态
【发布时间】:2017-05-22 05:06:21
【问题描述】:

我有许多 aspx 页面,这些页面是创建最终表单的过程。例如,

选择项目类型页面 -> 选择项目颜色页面 -> 选择项目数量页面 -> 完成页面

每个页面都有一个下一页和上一页按钮,当我从第一页移动到第二页并且用户单击上一个按钮返回到第一页时,控件的状态将被重置,失去所有用户的输入

我想以这种方式将控件保存在会话中:

protected void btn_Next_Click(object sender, EventArgs e)
{
    if (validateForm() == true)
    {
        Session["test1"] = RadioButtonList1;
        Response.Redirect("nextpage.aspx");
    }
}    

并以这种方式加载:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (Session["test1"] != null)
            RadioButtonList1 = (RadioButtonList)Session["test1"];

        getInfo();
    }
}

但是,我选择了 radiobuttonlist1 中的第二项,当我移动到第二页并返回到第一页时,它没有加载 radiobuttonlist1 的确切状态。调试显示它进入了RadioButtonList1 = (RadioButtonList)Session["test1"]; 代码

【问题讨论】:

  • 您是否在页面加载中检查了Session["test1"] 的值...是否有所需的数据...?
  • 为什么不使用向导控件。检查thisthis(如果你想为MVC实现)
  • @Abi 不,这是一个空的单选按钮列表
  • @kashi_rock 我没有在这个项目中使用 MVC,但它看起来很有趣,会查找它

标签: c# asp.net session


【解决方案1】:

你可以试试这个吗:

为每个列表项设置 value 属性并在这样的会话中检索选定的值

Session["test1"] = RadioButtonList1.SelectedItem.Value;

在加载时

RadioButtonList1.SelectedValue = (String) Session["test1"];

【讨论】:

  • 我不需要值,我需要知道单选按钮列表的状态,例如检查了什么
猜你喜欢
  • 2013-05-09
  • 1970-01-01
  • 2011-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多