[英]Posting User Input from one page to another
I'm creating an ASP.NET webpage that allows for personnel information to be entered into textboxes (firstName, lastName, payRate, startDate, endDate). 我正在创建一个ASP.NET网页,该页面允许将人员信息输入文本框(firstName,lastName,payRate,startDate,endDate)。 Once entered and the "submit" button is clicked, a couple of validation rules are checked and if all fields are validated correctly, then the information is passed to second page to be displayed (again inside a multi-line textbox).
输入并单击“提交”按钮后,将检查几个验证规则,如果所有字段都正确验证,则信息将传递到第二页进行显示(再次在多行文本框中)。
Now the problem that I am encountering is that when the submit button is pushed, the text box on the second page doesn't display the information entered; 现在,我遇到的问题是,当按下“提交”按钮时,第二页上的文本框不显示输入的信息。 instead it displays the following:
而是显示以下内容:
"System.Web.UI.WebControls.TextBox" <-- this is displayed five times (once for each text field) “ System.Web.UI.WebControls.TextBox” <-显示五次(每个文本字段一次)
Below is an exempt from the submit button event handler from the first page and the page load handler from the verified information page. 以下是第一页的提交按钮事件处理程序和已验证信息页的页面加载处理程序的豁免。
protected void btnSubmit_Click(object sender, EventArgs e)
{
string Msg = "";
Boolean validatedState = true;
//validating first name text box
if (Request["txtFirstName"].ToString().Trim() == "")
{
txtFirstName.BackColor = System.Drawing.Color.Yellow;
Msg = "Please enter first name";
lblError.Text += Msg;
validatedState = false;
}
else
{
txtFirstName.BackColor = System.Drawing.Color.White;
Msg = "";
lblError.Text = "";
validatedState = true;
}
These if statements are repeated for all five fields and then the information is stored in session state and transfer to the next page like so: 对于所有五个字段重复这些if语句,然后将信息存储在会话状态中,并像下面这样转移到下一页:
if (validatedState)
{
Session.Add("txtFirstName", txtFirstName);
Session.Add("txtLastName", txtLastName);
Session.Add("txtPayRate", txtPayRate);
Session.Add("txtStartDate", txtStartDate);
Session.Add("txtEndDate", txtEndDate);
Server.Transfer("frmPersonnelVerified.aspx");
}
Below is the page load handler from the verified information page that is meant to retrieve and display the information from session object. 以下是经过验证的信息页面中的页面加载处理程序,用于从会话对象中检索和显示信息。
protected void Page_Load(object sender, EventArgs e)
{
//requesting information from personnel form; displaying in multi-line textbox called txtVerifiedInfo
txtVerifiedInfo.Text = Session["txtFirstName"].ToString() +
Session["txtLastName"].ToString() +
Session["txtPayRate"].ToString() +
Session["txtStartDate"].ToString() +
Session["txtEndDate"];
}
as Khan said: 如汗所说:
Session.Add("txtFirstName", txtFirstName);
should be 应该
Session.Add("txtFirstName", txtFirstName.Text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.