Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法获取在文本框中输入的值_C#_Asp.net_Webforms - Fatal编程技术网

C# 无法获取在文本框中输入的值

C# 无法获取在文本框中输入的值,c#,asp.net,webforms,C#,Asp.net,Webforms,我没有得到第一个用户和姓氏。请告诉我最新情况 它的表单1:它向表单显示基于文本的System.Web.UI.WebControls.TextBoxSystem.Web.UI.WebControls.TextBox <html> <head id="Head1" runat="server"> </head> <body> <form id="form1" runat="server"> <div>

我没有得到第一个用户和姓氏。请告诉我最新情况 它的表单1:它向表单显示基于文本的
System.Web.UI.WebControls.TextBoxSystem.Web.UI.WebControls.TextBox

<html>
 <head id="Head1" runat="server">

 </head>
 <body>
   <form id="form1" runat="server">
     <div>
       <h3>SessionStateData</h3>
       <table>
       <tr>
          <td>FirstName:</td><td><asp:TextBox ID="txtfName" runat="server"/></td>
       </tr>
       <tr>
          <td>SecondName:</td><td><asp:TextBox ID="txtlName" runat="server"/></td>
       </tr>
       <tr>
          <td></td>
          <td> 
              <asp:Button ID="btnSubmit" runat="server" Text="Submit"  OnClick="btnSubmit_Click" />
          </td>
       </tr>
       </table>
     </div>
  </form>
</body>
</html>
表格2:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">

    </head>
    <body>
       <form id="form1" runat="server">
    <div>
     <h3>Default2.aspx</h3>
   <table>
      <tr>
     <td colspan="2">Welcome <b><asp:Label ID="lblString" runat="server"/></b></td>
      </tr>
     <tr>
      <td>Your FirstName: </td><td><b><asp:Label ID="lblfName" runat="server"/></b></td>
      </tr>
      <tr>
      <td>Your SecondName </td><td><b><asp:Label ID="lbllName" runat="server"/></b></td>
     </tr>
        <tr><td></td><td> </td></tr>
    </table>
   </div>
     </form>
    </body>
    </html>

您需要使用
TextBox
控件的
Text
属性来获取值

替换此项:

    Session["FirstName"] = txtfName;
    Session["SecondName"] = txtlName;
为此:

    Session["FirstName"] = txtfName.Text;
    Session["SecondName"] = txtlName.Text;
完整代码:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    Session["FirstName"] = txtfName.Text;
    Session["SecondName"] = txtlName.Text;
    Response.Redirect("WebForm2.aspx");
}
    Session["FirstName"] = txtfName.Text;
    Session["SecondName"] = txtlName.Text;
protected void btnSubmit_Click(object sender, EventArgs e)
{
    Session["FirstName"] = txtfName.Text;
    Session["SecondName"] = txtlName.Text;
    Response.Redirect("WebForm2.aspx");
}