問題描述
我只是想知道是否有辦法將我的 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() 應(yīng)該在 .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?
推薦答案
您可以在任何服務(wù)器控件上執(zhí)行此操作,并且此按鈕通過定義runat=server
"成為服務(wù)器控件.問題可能出在您對事件的定義中:
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...
這篇關(guān)于ASP.NET/HTML:ASP.NET (.cs) 中 HTML 按鈕的 onClick 屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!