如何使用asp.net内容页访问文本框值以隐藏代码?

如何使用asp.net内容页访问文本框值以隐藏代码?,asp.net,Asp.net,我在我的aspx文件中有一个文本框和一个按钮,我想在单击按钮时获取文本框值以代码隐藏,我以前实现过这一点,但现在我使用asp:内容页,但现在我无法获取代码隐藏的值 我的aspx <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="test1.test" %> <asp:Content ID

我在我的aspx文件中有一个文本框和一个按钮,我想在单击按钮时获取文本框值以代码隐藏,我以前实现过这一点,但现在我使用asp:内容页,但现在我无法获取代码隐藏的值

我的aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="test1.test" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<body>
<div>
<input type="text" runat="server" id="abc" />
<asp:Button 
 ID="Button1" 
 runat="server" 
 Text="Search" 
class="btn"
OnClick="Button1_Click"
/>
 </div>
</body>
</asp:Content>

但是我无法在按钮单击中获取文本框值。

您的控件没有名称,因此它不会以表单的形式发布,您可以将其读取为
请求。表单[“abc”]
。WebForms将生成其名称,类似于
master00$formName$abc
。您可以在HTML源代码中对此进行检查,但在页面上添加更多控件后,每个请求或更改可能会有所不同。因此,自动生成时不应使用此字段

要么给它起个名字:

<input type="text" runat="server" id="abc" name="abc" />

因为您已经为输入控件提供了runat

 <input type="text" runat="server" id="abc" />

//这里不需要使用Request.Form,因为输入现在是一个服务器控件

我很惊讶你没有尝试过
abc.Value
或使用
TextBox
abc.Text
它不是
TextBox
,所以他需要
abc.Value
@Tim I,尽管WebForms将
识别为一个文本框并生成一个
文本框foo
成员。我想我不应该凭记忆打字,谢谢P
string textBoxValue = abc.Value;
 <input type="text" runat="server" id="abc" />
  string txtboxvalue = abc.Value;