繁体   English   中英

如何在代码隐藏中获取文本框的值

[英]How to get the value of a textbox in code-behind

HTML:

<input type="text" runat="server" value="" placeholder="Search" id="searchB" class="styledTB searchB floatLeft" />

C#:

string strSMain;
protected void Page_Load(object sender, EventArgs e)
{
    tbSearchMain = (System.Web.UI.WebControls.TextBox)sender;

    strSMail = tbSearchMain.text; // gives me the following error: Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP.site_master' to type 'System.Web.UI.WebControls.TextBox'.

    strSMain = searchB.text; //.Text is not an option for me
}

请帮助我解决问题。

我正在创建一个Web应用程序。 控件位于MasterPage中。

用这个:

<input id="searchB" x:Name="searchB" type="text" runat="server" value="" placeholder="Search" class="styledTB searchB floatLeft" />

id属性用于客户端。 x:Name用于服务器端操作

我不确定,但是没有文本框会发送给Page_Load()函数。

检查DataContext属性及其工作方式。

http://www.wpf-tutorial.com/data-binding/using-the-datacontext/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM