简体   繁体   English

将输入类型的OnClick与C#方法相关联

[英]Associate OnClick of input type with C# method

On entering a text in a Textbox element in asp net, owed to the OnTextChanged attribute, the method TextButton1_TextChanged from code behind is triggered: 由于OnTextChanged属性,在asp网络的Textbox元素中输入文本时,将触发来自后面代码的TextButton1_TextChanged方法:

<asp:TextBox ID="TextButton1" runat="server" value="" OnTextChanged="TextButton1_TextChanged"> </asp:TextBox>`

What is a way to obtain the same functionality with an input type text like: 使用输入类型文本来获得相同功能的方法是什么:

<input type="text" id="InputType1" placeholder="Placeholder here">

I tried this with no effect: 我试了一下没有任何效果:

<input type="text" id="InputType1" onclick ="TextButton1_TextChanged" >

如果希望它成为等效的OnClick()或使用OnServerChanged="TextButton1_TextChanged TextButton1_TextChanged等效于textbox_change等效,请使用runat="server"OnServerClick="TextButton1_TextChanged" 。有关OnServerChanged的更多详细信息,请链接:( https://msdn.microsoft.com /en-us/library/system.web.ui.htmlcontrols.htmlinputtext.onserverchange(v=vs.110).aspx

The simple answer: use a TextBox . 简单的答案:使用TextBox But if you have to use the HtmlInputText -control you could handle the ServerChange -event : 但是,如果必须使用HtmlInputText ServerChange可以处理ServerChange -event

<input type="text" id="InputType1" runat="server" ServerChange="TextButton1_TextChanged" >

codebehind: 代码背后:

protected void Server_Change(object sender, EventArgs e) 
{
   Console.WriteLine("You typed: " + InputType1.Value);
}

But note that you don't have AutoPostBack , so you have to wait until the next postback is triggered, fe from a button. 但是请注意,您没有AutoPostBack ,因此必须等到下一次回发被触发(例如,通过按钮)。

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

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