简体   繁体   English

将用户输入从一页发布到另一页

[英]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.

相关问题 将数据从一个asp.net页发布到另一个 - Posting data from one asp.net page to another 单击按钮将数据从一个asp.net页发布到另一页 - Posting datas from one asp.net page to another when click a button 使用cookie将用户信息从一个剃刀页面传送到另一个剃刀页面 - Carry user info from one razor page to another using cookies 从一个页面导航到另一页面时,Signalr注销用户 - Signalr logging out user when navigating from one page to another 如何从另一个页面重定向到主页而不丢失用户在主页上的输入数据? - How to redirect to Home page from another page without loosing input data by user at Home page? C#将[FromBody]数据从一个控制器发布到另一个 - C# POSTing [FromBody] data from one controller to another 如何使用查询字符串和输入表单将数据从一页发送到另一页? - How to send data from one page to another page with querystring and input form? 从一页滑到另一页 - Swipe from one page to another 根据来自表单的用户输入,将一个表的主键插入另一个表 - Insert primary key from one table into another based on user input from a form 如何将循环的用户输入从一个类方法调用到另一个类方法中? - how to call a looped user input from one class method into another class method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM