我應該改變frmPersonnelVerified後面的代碼以獲取來自會話狀態項的值。更改背後的代碼
這裏是我的會話狀態代碼:
public partial class frmPersonnel : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
//Checking validation for the text boxes
if (string.IsNullOrEmpty((txtFirstName.Text ?? string.Empty).Trim()))
{
txtFirstName.BackColor = System.Drawing.Color.Yellow;
lblError.Text += "Please enter first name! <br />";
}
if (string.IsNullOrEmpty((txtLastName.Text ?? string.Empty).Trim()))
{
txtLastName.BackColor = System.Drawing.Color.Yellow;
lblError.Text += "Please enter last name! <br />";
}
if (string.IsNullOrEmpty((txtPayRate.Text ?? string.Empty).Trim()))
{
txtPayRate.BackColor = System.Drawing.Color.Yellow;
lblError.Text += "Please enter pay rate! <br />";
}
if (string.IsNullOrEmpty((txtStartDate.Text ?? string.Empty).Trim()))
{
txtStartDate.BackColor = System.Drawing.Color.Yellow;
lblError.Text += "Please enter start date! <br />";
}
if (string.IsNullOrEmpty((txtEndDate.Text ?? string.Empty).Trim()))
{
txtEndDate.BackColor = System.Drawing.Color.Yellow;
lblError.Text += "Please enter end date! <br />";
}
DateTime dt1;
DateTime dt2;
dt1 = DateTime.Parse(txtStartDate.Text);
dt2 = DateTime.Parse(txtEndDate.Text);
if (DateTime.Compare(dt1, dt2) > 0)
{
//Checking if the end date is greater than the start date
txtStartDate.BackColor = System.Drawing.Color.Yellow;
txtEndDate.BackColor = System.Drawing.Color.Yellow;
lblError.Text += "Start Date must not be greater than End Date! <br />";
}
else
{
//output information if correct validation
Session["txtFirstName"] = txtFirstName.Text;
Session["txtLastName"] = txtLastName.Text;
Session["txtPayRate"] = txtPayRate.Text;
Session["txtStartDate"] = txtStartDate.Text;
Session["txtEndDate"] = txtEndDate.Text;
Server.Transfer("frmPersonalVerified.aspx");
}
}
catch (Exception ex)
{
}
}
}
我有一個提交按鈕按下時應該輸入上述信息到另一個頁面上的文本框,如果正確驗證。現在它不這樣做。
這是我在frmPersonnalVerified代碼:
public partial class frmPersonnelVerified : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Inputs information from frmPersonnel and places it into the
//textbox called "txtVerifiedInfo"
txtVerifiedInfo.Text = Request["txtFirstName"] +
"\n" + Request["txtLastName"] +
"\n" + Request["txtPayRate"] +
"\n" + Request["txtStartDate"] +
"\n" + Request["txtEndDate"];
}
}
你可以使用String.Join代替字符串連接 – Guillaume86