calling a web method from clientside using jquery ajax method - not
calling method rather going into pageload
I click my edit button,it enters button click function in javascript.When
ajax() is executed the control goes to page load of WebForm rather than
directly calling update() of webform which I'm mentioning as [ url:
"WebForm1.aspx/update",] in ajax().Why not my update function is invoked
?? I'm having master page for my webform and the button is an asp:control
my aspx page looks like this
This is my javascript
$(document).ready(function () {
$("input[id*='edit']").click(function () {
var userdata = {};
userdata["Name"]="Saran";
var DTO = { 'userdata' : userdata};
$.ajax({
type: "POST",
contenttype: "application/json; charset=utf-8",
url: "WebForm1.aspx/update",
data: JSON.stringify(DTO),
datatype: "json",
success: function (result) {
//do something
alert("SUCCESS = " + result);
console.log(result);
},
error: function (xmlhttprequest, textstatus, errorthrown) {
alert(" conection to the server failed ");
console.log("error: " + errorthrown);
}
});//end of $.ajax()
return false;
});//eof button click
});
and my webform looks like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using Payoda.Assignments.BusinessLayer;
namespace Payoda.Assignments.LoginApplication
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string update(string userdata)
{
return "success";
}
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/MyMasterPage.Master"
AutoEventWireup="true" CodeBehind="TrialPage.aspx.cs"
Inherits="Application.TrialPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="Scripts/jquery-1.10.2.js"></script>
<script src="Scripts/TrialScript.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Contents" runat="server">
<asp:Button ID="editLink" runat="server" Text="MY BUTTON" />
</asp:Content>
No comments:
Post a Comment