如何在 ASP C# 中从文本框读取数据

本文关键字:文本 读取 数据 ASP | 更新日期: 2023-09-27 18:34:48

从文本框读取数据时出错,下面是 XML 代码:

    <asp:Button ID="btnSearch" runat="server" Style="z-index: 100; left: 513px; position: absolute;
        top: 340px" Text="Search" Width="188px"/>
    <asp:TextBox ID="MyTB" runat="server" Style="z-index: 101; left: 365px; position: absolute;
        top: 302px" Width="493px"/>

这是我调用文本框"MyTB"从中读取数据的代码:

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string text = MyTB.Text;
        string[] textArr = text.Split(new char[] { ' ', ''n', ',' });
    }

该 XML 代码 :

<div>
    <asp:Button ID="btnSearch" runat="server" Style="z-index: 100; left: 513px; position: absolute;
        top: 340px" Text="Search" Width="188px"/>
    <asp:TextBox ID="MyTB" runat="server" Style="z-index: 101; left: 365px; position: absolute;
        top: 302px" Width="493px"/>

</div>

如何在 ASP C# 中从文本框读取数据

代码似乎是正确的。您可以检查页面的设计器.cs文件,以确保它定义了MyTB,例如

protected global::System.Web.UI.WebControls.TextBox MyTB;