admin管理员组文章数量:1401818
How to call server side function using HTML anchor tag.
Here I showed some example of my code.
HTML
<html xmlns="">
<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
}
How to call server side function using HTML anchor tag.
Here I showed some example of my code.
HTML
<html xmlns="http://www.w3/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
}
Share
Improve this question
asked Aug 25, 2015 at 15:01
user5264652user5264652
1
- You need to use AJAX to do this – muddyfish Commented Aug 25, 2015 at 15:06
2 Answers
Reset to default 4Try like this, create one submit button and hide that
HTML
<html xmlns="http://www.w3/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>
You can either add runat="server"
and OnServerClick="btnSubmit_Click"
to your anchor tag like this:
<a href="" runat="server" OnServerClick="btnSubmit_Click"> Update </a>
Or you can use asp:LinkButton
. This has an OnClick
attribute that will call the method in your code behind:
<asp:LinkButton ID="LinkButton1" runat="server"
OnClick="LinkButton1_OnClick">Update</asp:LinkButton>
protected void LinkButton1_OnClick(object sender, EventArgs e)
{
//Update User Details
}
本文标签: javascripthow to call a c function in anchor tag click eventStack Overflow
版权声明:本文标题:javascript - how to call a c# function in anchor tag click event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744290553a2599090.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论