问题描述
我只是想知道是否有办法将我的 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 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!