0

我有一个向导控件,我有这个代码

    protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        if (Wizard1.ActiveStepIndex == 0)
        {
            if (firstName != null && lastName != null)
            {
                Wizard1.ActiveStepIndex = 1;
            }
            else
            {
                e.Cancel = true;
            }
        }
    }

当代码到达 firstName 和 lastName 时,它​​们都为空,我在上面的前一个方法中填充了它们,在此事件触发之前它们不是空的。我的搜索只让我对原因进行验证,这是罪魁祸首吗?

4

1 回答 1

2

除非您将它们存储在 ViewState 或 Session 或数据库中,否则属性将在回发时丢失。

例如视图状态

  public string Firstname{

    get {

return ViewState["Firstname"] == null ?String.Empty :(string)ViewState["Firstname"];

    }
    set { ViewState["Firstname"] = value; }
}
于 2014-01-23T22:06:13.197 回答