i tried like this code it works.only if the methos is static.
if i remove static for method it not invokes. what is the reason can u please tell me if u know.
in that method it not accepts asp.net controls .in that code if i remove the comment for "label1.text".it shows error it not exists in current context.
how to handle that label1.text in that method if u know can please tell me sir.
<script type="text/javascript">
$(function () {
$("[id*=Button1]").click(function () {
//alert('ok');
var obj = {};
obj.N1 = $.trim($("[id*=TextBox1]").val());
obj.N2 = $.trim($("[id*=TextBox2]").val());
$.ajax({
type: "POST",
url: "WebForm1.aspx/Button",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
// for laBel
$("#vv").text(r.d);
//for textBox
//$("#vv").val(r.d);
//alert(r.d);
}
});
return false;
});
});
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="ADD" />
[System.Web.Services.WebMethod]
public static string Button(string N1, string N2)
{
WebService1 aa = new WebService1();
int a, z;
a = Convert.ToInt32(N1);
z = Convert.ToInt32(N2);
int result1 = aa.add(a,z);
//Label1.Text = result1.ToString();
return result1.ToString();
}