Monday, March 26, 2012

PageMethods is undefined

Hi there

I have a simple page that calls a server side page method via the scriptmanager / page methods detailed on this site. This has worked fine recently when until I updated our dev team to use the new asp.net ajax 1.0.

Once I'd updated my web.config as per the doco all works fine on my pc but on all others when I call the server side method I get the client script error " PageMethods Is 'Undefined' ". I am sure this is an environmental issue but I would appreciate any tips on how to figure out what is going on!

To update one of the boxes (eg our test server) I did the following steps.

    Uninstall previous ASP.net Ajax (RC1)Install new versionUpdate web.config as per instructions in the doco

Here is my source code

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="AddNote.aspx.cs" Inherits="controls_AddNote" EnableViewState="true" %><%@dotnet.itags.org. Import Namespace="System.Web.Services" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Add a note to this cell</title> <link rel="stylesheet" type="text/css" href="../css/calumo default.css" /> </head> <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0"> <script type="text/javascript" language="javascript"> function PageMethodCall() { var TicketId=parseInt($get("inpTicketId").value); var DataSource=$get("inpDataSrc").value; var Catalog=$get("inpCatalog").value; var Cube=$get("inpCube").value; var DataPointMdx=$get("inpMdx").value; var NoteValue=$get("taNote").value; if(NoteValue.length>0) PageMethods.SendNote(TicketId,DataSource,Catalog,Cube,DataPointMdx,NoteValue,OnSucceeded); } // This is the callback function // that process the page method call // return value. function OnSucceeded(result) { // Display the result. if(result==1) window.close(); else alert("Calumo Server Exception:-" + result); } function Validate() { if($get("taNote").innerText.length>0) $get("btnSend").value="Send"; else $get("btnSend").value="Close"; } </script> <form id="frmAddNote" runat="server" target="_self"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <input runat="server" type="hidden" id="inpTicketId" value="" /> <input runat="server" type="hidden" id="inpDataSrc" value="" /> <input runat="server" type="hidden" id="inpCatalog" value="" /> <input runat="server" type="hidden" id="inpCube" value="" /> <input runat="server" type="hidden" id="inpMdx" value="" /> <table id="Table1" runat="server" height="100%" width="95%" cellpadding="0" cellspacing="0"> <tr id="trHeader" > <td><img alt="" src="../images/Calumo/top_bar.jpg"/></td> </tr> <tr><td> </td></tr> <tr id="trBody"> <td id="tdNoteArea" align="center">  <textarea cols="10" runat="server" style="height:100%;width:650px;" id="taNote" rows="10" ></textarea> </td> </tr> <tr><td> </td></tr> <tr id="trFooter"> <td style="padding-right:20px;width:100%" id="tdClose" align="right"> <input id="btnSend" type="button" value="Send" onclick="javascript:PageMethodCall();" /> </td> </tr> </table> </form> </body></html>

and here is the server code

 [WebMethod()]public static string SendNote(int TicketId,string DataSource,string Catalog,string Cube,string DataPointMdx,string NoteValue) {try {// Add a note to the server code and return a sample msgreturn"It Works"; }catch(Exception ex) {return ex.Message; } }

Any hints on troubleshooting would be greatly appreciated

Thanks in advance

Graham

Try settingEnablePageMethods="true"

<

asp:ScriptManagerID="ScriptManager1"runat="server"EnablePageMethods="true">

Yep thats it! Would probably be a good idea to add to the update doco

thanks


Was that missing in the documentation somewhere? We'll happily fix it... just point me to where it's missing.


There should probably be a section on Page Methods...in the docs that is accessible by the left hand side index..

Also, for whatever reason - the UpdatePanels UpdateMode is set by default to "Always" a special highlight in the docs should indicate this is the default and to change it to conditional for partial rendering / asynchronous updates. I was kinda surprised when investigating some of the post and issues on always full postbacks - that when I just dragged and dropped an updatepanel in designer - it defaulted to "Always"... kinda missing the purpose I think as if you are releasing this - then the default should err on side of the Ajax technology it is supposed to provide and this is a change I think from the RCs but not positive as I always declare everything anyways... but alot of folks just drag and drop and assume they are getting the settings for exploiting the Ajax enviroment...


I followed this docohttp://ajax.asp.net/documentation/Migration_Guide_RC_to_RTM.aspx

and unless I skipped over it I didn't find any reference to the EnablePageMethods

thanks again


I agree! Where can you find reference and documentation to PageMethods ? I use the block of code on this post as my reference right now ..


http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx

I agree this would be nice to see in the "differences" docs. I'll see if it can be added.


Just wanted to say thanks, all.

I was trying to get a method to run from a page (both in the .aspx file and in the code behind) and kept getting the js error of "PageMethods" not found. Adding that attribute to the ScriptManager cured the problem.

Pete.

No comments:

Post a Comment