<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Jquery</title>
<script type="text/javascript" src="scripts/jquery-1.4.2.js"></script>
<script type="text/javascript"> jQuery(document).ready(function () {
$('#btnmore').click(function () {
$('<%=btnSave.ClientID%>').click();
alert('done');
$.ajax({type: 'POST',
contentType: 'application/json; charset=utf-8',
data: '{}',
dataType: 'json',
url: 'Default.aspx/btnSave_Click',
success: function(result){
alert(result);} });
});
});</Script>
</head>
<body>
<form id="form1" runat="server">
<asp:scriptManager id="script1"></asp:scriptManager>
<div>
<table>
<tr>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
<input type="button" id="btnmore" value="More" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Server side code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Services;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string MyMethod()
{
return "abc";
}
[WebMethod]
protected void btnSave_Click(object sender, EventArgs e)
{
Response.Write("abc");
}
}
Why not just use:
Note that you will need to get the actual name of btnSave, because it will probably be in a naming container. Something like this should get the correct id: