c# - How to call ajax from grid view and redirect in same page -


$.ajax({     type: "post",     url: "default4.aspx.cs/saveuser",     data: "{ 'taskid': '" + taskid + "'}",     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function (data) {         var flag = data;         if (flag == "fail") {             alert("task in use");         }         else {             alert("task not in use");         }     } }); 

i have function in called saveuser this:

public void saveuser() {     //something do; } 

in default4.aspx.cs when call it's not executing. tried, , calling javascript because gave alert there, it's not entering ajax. can help?

your method should static , decorated [webmethod] attribute. parameter named taskid should passed method.

[system.web.services.webmethod] public static void saveuser(int taskid) {     //something do; } 

you don't need give path .cs extension. remove .cs url part of ajax

url: "default4.aspx/saveuser", 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -