You can use the PageMethods to call server side function (C#) from ClientSide(Javascript)
Please try the below implementation
1) Add a script Manager to your page and set the 'EnablePageMethods' property of script manager to True.
<asp:ScriptManager ID="ScriptManager2" runat="server" EnablePageMethods="true"/>
2) Add Javascript function to the body section of page
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function CallingServerSideFunction() {
PageMethods.Add(1,2);
}
</script>
</form>
</body>
3) Change you method like given below
//Please note that the method should be a Static and WebMethod.
[System.Web.Services.WebMethod]
public static void Add(int x, int y)
{
int k = x + y;
//Your Logic comes here
}
4) Calling the Javascript function
<input id="Button2" type="button" value="FunctionCall" onclick="CallingServerSideFunction()" />
Thanks,
A2H
My Blog
Only4ram, if this helps please login to Mark As Answer. | Alert Moderator