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 属性
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
