上代码先
LoadControl.csnamespace ASPNET20
{
public partial class LoadControl : System.Web.UI.Page
{
private List<String> _steps;
private Control _currentControl;
public int StepIndex
{
get
{
if(ViewState["StepIndex"]!=null)
{
return (int) ViewState["StepIndex"];
}
return 0;
}
set
{
ViewState["StepIndex"] = value;
}
} protected void Page_PreRender()
{
this.btnPrevious.Enabled = StepIndex > 0 ? true : false;
this.btnNext.Enabled = StepIndex < _steps.Count - 1 ? true : false;
} protected void Page_Load(object sender, EventArgs e)
{
_steps = new List<string>
{
"~/UserControls/Step1.ascx",
"~/UserControls/Step2.ascx",
"~/UserControls/Step3.ascx"
};
LoadSteps();
} protected void LoadSteps()
{
_currentControl = Page.LoadControl(_steps[StepIndex]);
// _currentControl.ID = "xxx";
this.plhSteps.Controls.Clear();
if (_currentControl != null)
{
this.plhSteps.Controls.Add(_currentControl);
((IWizardStep) _currentControl).LoadStep();
}
} protected void btnPrevious_Click(object sender, EventArgs e)
{
if (StepIndex >0)
{
StepIndex--;
LoadSteps();
}
} protected void btnNext_Click(object sender, EventArgs e)
{
if (((IWizardStep)_currentControl).NextStep() && StepIndex<_steps.Count -1)
{
StepIndex++;
LoadSteps();
}
} }
}Step1.ascx public void LoadStep()
{
if(Session["FirstName"] != null)
{
txtFirstName.Text = (string) Session["FirstName"];
}
if (Session["LastName"] != null)
{
txtLastName.Text = (string)Session["LastName"];
}
} public bool NextStep()
{
if(Page.IsValid)
{
Session["FirstName"] = txtFirstName.Text;
Session["LastName"] = txtLastName.Text;
return true;
}
return false;
}Step2.ascx public void LoadStep()
{
if(Session["FavoriteColor"] != null)
{
this.txtFavColor.Text = Session["FavoriteColor"].ToString();
}
}
public bool NextStep()
{
if(Page.IsValid)
{
Session["FavoriteColor"] = txtFavColor.Text;
return true;
}
return false;
}Step3.ascx public void LoadStep()
{
if (Session["FirstName"] != null )
{
txtFirstName.Text = Session["FirstName"].ToString();
}
if (Session ["LastName"] != null)
{
txtLastName.Text = Session["LastName"].ToString();
}
if (Session ["FavoriteColor"]!=null)
{
txtFavColor.Text = Session["FavoriteColor"].ToString();
}
}
public bool NextStep()
{
return false;
}
请注意 // _currentControl.ID = "xxx";
问题是
如果没有这一句的话 在 Step2 中,即使输入了color, Page.IsValid 依然等于 false; 显示错误信息。
如果有着句话, Step2中, 输入color , Page.IsValid == true,
LoadControl.csnamespace ASPNET20
{
public partial class LoadControl : System.Web.UI.Page
{
private List<String> _steps;
private Control _currentControl;
public int StepIndex
{
get
{
if(ViewState["StepIndex"]!=null)
{
return (int) ViewState["StepIndex"];
}
return 0;
}
set
{
ViewState["StepIndex"] = value;
}
} protected void Page_PreRender()
{
this.btnPrevious.Enabled = StepIndex > 0 ? true : false;
this.btnNext.Enabled = StepIndex < _steps.Count - 1 ? true : false;
} protected void Page_Load(object sender, EventArgs e)
{
_steps = new List<string>
{
"~/UserControls/Step1.ascx",
"~/UserControls/Step2.ascx",
"~/UserControls/Step3.ascx"
};
LoadSteps();
} protected void LoadSteps()
{
_currentControl = Page.LoadControl(_steps[StepIndex]);
// _currentControl.ID = "xxx";
this.plhSteps.Controls.Clear();
if (_currentControl != null)
{
this.plhSteps.Controls.Add(_currentControl);
((IWizardStep) _currentControl).LoadStep();
}
} protected void btnPrevious_Click(object sender, EventArgs e)
{
if (StepIndex >0)
{
StepIndex--;
LoadSteps();
}
} protected void btnNext_Click(object sender, EventArgs e)
{
if (((IWizardStep)_currentControl).NextStep() && StepIndex<_steps.Count -1)
{
StepIndex++;
LoadSteps();
}
} }
}Step1.ascx public void LoadStep()
{
if(Session["FirstName"] != null)
{
txtFirstName.Text = (string) Session["FirstName"];
}
if (Session["LastName"] != null)
{
txtLastName.Text = (string)Session["LastName"];
}
} public bool NextStep()
{
if(Page.IsValid)
{
Session["FirstName"] = txtFirstName.Text;
Session["LastName"] = txtLastName.Text;
return true;
}
return false;
}Step2.ascx public void LoadStep()
{
if(Session["FavoriteColor"] != null)
{
this.txtFavColor.Text = Session["FavoriteColor"].ToString();
}
}
public bool NextStep()
{
if(Page.IsValid)
{
Session["FavoriteColor"] = txtFavColor.Text;
return true;
}
return false;
}Step3.ascx public void LoadStep()
{
if (Session["FirstName"] != null )
{
txtFirstName.Text = Session["FirstName"].ToString();
}
if (Session ["LastName"] != null)
{
txtLastName.Text = Session["LastName"].ToString();
}
if (Session ["FavoriteColor"]!=null)
{
txtFavColor.Text = Session["FavoriteColor"].ToString();
}
}
public bool NextStep()
{
return false;
}
请注意 // _currentControl.ID = "xxx";
问题是
如果没有这一句的话 在 Step2 中,即使输入了color, Page.IsValid 依然等于 false; 显示错误信息。
如果有着句话, Step2中, 输入color , Page.IsValid == true,
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货