C# 类似于 ASP.NET 按钮的 HTML 按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8887933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML Button like a ASP.NET Button
提问by Irakli Lekishvili
How can i use HTML button like an ASP.NET Button?
我如何像 ASP.NET 按钮一样使用 HTML 按钮?
采纳答案by adatapost
Html tags attributed with runat="server"are called HtmlControls and you need to handle ServerClickevent.
归属于的 Html 标签runat="server"称为 HtmlControls,您需要处理ServerClick事件。
Markup
标记
<button id="button1" runat="server" onserverclick="doIt" >Submit</button>
Code behind
背后的代码
protected void doIt(object sender, EventArgs e)
{
Response.Write("Hello World!!!");
}
回答by Icarus
Add runat=server to the HTML definition as so:
将 runat=server 添加到 HTML 定义中,如下所示:
<button id="btnserver" runat="server" .../>
That will make it a server control
这将使它成为服务器控件
回答by Sid
Basically you can turn html elements in to asp.net by adding runat="server"attribute.In that way you can use html button as asp.net in following way:
基本上,您可以通过添加runat="server"属性将 html 元素转换为 asp.net。通过这种方式,您可以通过以下方式将 html 按钮用作 asp.net:
<button id="btnOne" runat="server"></button>
Now if you have click events for your button, you can use the onserverclick attribute:
现在,如果您的按钮有点击事件,您可以使用 onserverclick 属性:
<button id="btnOne" runat="server" onserverclick="btnOne_Click"></button>

