I'm attempting to execute this code behind function :
protected void Insert(object sender, EventArgs e)
{
blah blah blah code
this.BindGrid();
}
Within the .aspx file, I have a JavaScript function that appears as follows:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<asp:Button ID="Button2" runat="server" Text="Call Button Click" Style="display:none" OnClick="Insert" />
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClientClick="return Validate();" Width="100" />
<script type="text/javascript">
function Validate()
{
var id = document.getElementById("txtStudentID").value;
Number(id);
var fn = document.getElementById("txtFirstName").value;
String(fn);
var ln = document.getElementById("txtLastName").value;
String(ln);
var cls = document.getElementById("txtClass").value;
String(cls);
var rn = document.getElementById("txtRollNumber").value;
Number(rn);
My code blah blah blah
document.getElementById("Button2").click();
PageMethods.Insert(onSuccessMethod, onFailMethod);
};
</script>
I am looking for a method to trigger the Insert function when I click the visible add button. I'm uncertain if my approach is correct or if there is a more efficient way to achieve this. Any assistance on how to call the Insert function from my JavaScript would be highly appreciated. I've tried various solutions found online without success. Thank you in advance.