I have button in aspx file as below :
<asp:Button ID="btnSave" Style="display: none;" runat="server" OnClick="btnSave_Click" />
Now in aspx.cs file I have below function.
protected void btnSave_Click(object sender, EventArgs e)
{
//some code
}
Now I want to call this btnSave_Click function from jquery, so I tried below but it is not calling this function..
function btnclick() {
$('#btnSave').click();
}
Any idea, why function is not calling from this jquery code to cs file ?
Thanks
2
Answers
You need to decorate a method in you aspx.cs file with WebMethod attribute like below:
Then you can make an AJAX call for it from Javascript.
I think the below link will explain:
https://www.c-sharpcorner.com/UploadFile/dacca2/static-webmethod-in-code-behind-webform/
You can "click" a button, and I often do this is place of coding out a webmethod.
So, add this to your button:
So, above then will allow your JavaScript code of this: