PageMethods not defined

I am configuring PageMethods to access server code using javascript. I get the error "PageMethods not defined" when I debug using firebug. server code also does not start.

I have the script manager "EnablePageMethods" set to true. My method is public and static, and it also sets the WebMethod attribute. However, I get the above error. Could this be because the script manager is located on the top-level main page, which has two child master pages, and then my page is called:

i.e.

Main main page (with script manager) → Main main page → Secondary main page → My page → My user control (using WebMethod)

Is it possible that this hierarchy is causing this problem?

This is a web method.

[System.Web.Services.WebMethod] public static void AddNote(string t) { int propid = 1; if (propid > 0) { //Call my method } } 

this is my javascript code:

  function editNodes(t) { alert('test1'); alert(t); PageMethods.AddNote(t,OnSuccess,OnFailure); alert('method called'); } function OnSuccess() { alert('Success'); if (!navigator.appName == 'Microsoft Internet Explorer') { window.location.href = window.location.href; } } function OnFailure(error) { alert('Error:' + error); } 

this is where i call it:

  <a href="#" class="btngeneral" onclick="javascript:editNodes(2);">Save</a> 
+4
source share
3 answers

Page methods do not work in either master pages or user controls.

If you move a method one level to your page, it should work.

I could never get a final answer to this question.

I suspect this is because aspx pages inherit from the Page class and ascx elements inherit from the UserControl class. As for the reasons for this, I'm not sure.

Personally, I would use a universal handler (.ashx) page and call this via javascript.

+16
source

set EnablePageMethods = "true"

  <ajaxToolkit:ToolkitScriptManager ID="scriptManager" runat="server" AsyncPostBackTimeout="99999999" EnablePageMethods="true" /> 

Hope this works for you.

+11
source

As far as I understand, PageMethods on usercontrol is not supported, and the threads below seem to confirm that

http://forums.asp.net/p/977525/1242935.aspx

ASP.NET AJAX Page Methods from UserControl

But I think there might be a workaround (not sure how effective this is in your scenario). You can write OneLine PageMethod in the page code, behind which the trainee should call the Controls method. Now you can call your page method from aspx and all you need to do.

Or you can use an alternative. An alternative way to use the page method inside asp.net user control

+4
source

All Articles