javascript - PageMethods is not defined Exception: Does not call the WebMethod in ASP.NET -
my webmethod not called pagemethod call in javascript function. here's code:
edit console says:
uncaught referenceerror: pagemethods not defined
js:
function profilefollowbuttonchange(cn) { if (cn.classname == "profile-page-owner-follow-button") { cn.classname = "profile-page-owner-follow-button-active"; alert("camefollow"); pagemethods.togglefollow("follow", onsuccess, onfailure); //does not trigger alert("camefollow"); //doesn't printed } else { cn.classname = "profile-page-owner-follow-button"; alert("cameunfollow"); pagemethods.togglefollow("unfollow", onsuccess, onfailure); //does not trigger alert("cameunfollow"); //doesn't printed } } function onsuccess() { } function onfailure() { }
c#:
[webmethod] public static void togglefollow(string command) { //does not reach point. }
and yes have added enablepagemethods="true" tag in scriptmanager tag.
however, have used 2 webmethods in same page 2 different purposes (two different names). issue? hardly think so, yall think?
it looks problem execution sequence of script , scriptmanager
. means make sure pagemethods
recognized javascript code, need load scriptmanager
first , fire javascript function. in logic, simple change required here. need use $(document).ready()
here in script make sure scriptmanager
first dom , script fired. should here.
$(document).ready(function () { function profilefollowbuttonchange(cn) { if (cn.classname == "profile-page-owner-follow-button") { cn.classname = "profile-page-owner-follow-button-active"; alert("camefollow"); pagemethods.togglefollow("follow", onsuccess, onfailure); //does not trigger alert("camefollow"); //doesn't printed } else { cn.classname = "profile-page-owner-follow-button"; alert("cameunfollow"); pagemethods.togglefollow("unfollow", onsuccess, onfailure); //does not trigger alert("cameunfollow"); //doesn't printed } } function onsuccess() { } function onfailure() { } });
just wrap script code $(document).ready()
, try it.
hope helps.
Comments
Post a Comment