C# 无法获取在文本框中输入的值
我没有得到第一个用户和姓氏。请告诉我最新情况 它的表单1:它向表单显示基于文本的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>
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");
}