gpt4 book ai didi

javascript - 如何在 anchor 标签点击事件中调用c#函数

转载 作者:太空宇宙 更新时间:2023-11-03 23:31:01 25 4
gpt4 key购买 nike

如何使用 HTML anchor 标记调用服务器端函数。

这里我展示了一些我的代码示例。

HTML

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server">
<title>Update</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="" onclick="btnSubmit_Click()">Update</a>
</div>
</form>
</body>
</html>

c#

protected void btnSubmit_Click(object sender, EventArgs e) 
{
//Update User Details
}

最佳答案

这样试试创建一个提交按钮并隐藏它

HTML

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server">
<title>Update</title>
<script language="javascript" type="text/javascript">
function fireServerButtonEvent(){
document.getElementById("btnSubmit").click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:button id="btnSubmit" runat="server" text="Submit" xmlns:asp="#unknown">
onclick="btnSubmit_Click" style="display:none" /></asp:button>
<a href="" onclick="fireServerButtonEvent()">Update</a>
</div>
</form>
</body>
</html>

关于javascript - 如何在 anchor 标签点击事件中调用c#函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32207526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com