ASP.NET/HTML: HTML button#39;s onClick property inside ASP.NET (.cs)(ASP.NET/HTML:ASP.NET (.cs) 中 HTML 按钮的 onClick 属性)
问题描述
我只是想知道是否有办法将我的 onClick 事件放入 .cs:
I just wanna find out if there's a way to put my onClick event inside .cs:
<button type="submit" runat="server" id="btnLogin" class="button" onclick="btnLogin_Click();">
Login_Click() 应该在 .cs 中的位置:
where Login_Click() should be inside .cs:
protected void btnLogin_Click(object sender, EventArgs e)
{
// do something
}
请注意,我不会在此处使用 ASP.NET 按钮,并且我不会将 Login_Click() 事件放入 .html/.aspx 中,因此我无法公开"我的代码.有什么建议吗?
Please do take note that I will not use ASP.NET button here, and that I will not put my Login_Click() event inside .html/.aspx so I can't 'expose' my codes. Any suggestions?
推荐答案
您可以在任何服务器控件上执行此操作,并且此按钮通过定义runat=server
"成为服务器控件.问题可能出在您对事件的定义中:
You can do that on any server control and this button is made a server control by defining "runat=server
". The problem is probably in your definition of the event:
<button ... runat="server" ... onServerClick="btnLogin_Click" />
那里不需要();
"...
除此之外,你能解释一下为什么你不在这里使用 <asp:Button>
因为我真的看不出有什么问题...
Apart from that can you explain why you don't use the <asp:Button>
here because I don't really see a problem with that...
这篇关于ASP.NET/HTML:ASP.NET (.cs) 中 HTML 按钮的 onClick 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET/HTML:ASP.NET (.cs) 中 HTML 按钮的 onClick 属性


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01