Monday, March 26, 2012

PageMethods is undefined when calling webservice from usercontrol

I have the following code to call a webservice in an aspx file. But the same code does not work in a usercontrol that I have created. I always get the message that 'PageMethods is undefined'. On the aspx page it generates the following:

<script type="text/javascript">
var PageMethods = { HelloWorld:function(s,onMethodComplete, onMethodTimeout, onMethodError) {return Web.Net.PageMethodRequest.callMethod("HelloWorld",{s:s}, onMethodComplete, onMethodTimeout, onMethodError); }
// -->

but in the usercontrol this variable is not generated. The following is the code in the aspx page which is very similar to the code in the user control. Please help!






publicstring HelloWorld(string s)


return"Hello '" + s +"'";






Enter your name:


<buttonid="buttonGo"onclick="return OnbuttonGo_click()">GO</button>



function OnbuttonGo_click()


//textbox string value passed as a param to the server method

PageMethods.HelloWorld(document.getElementById("nameTextBox").value, OnWebRequestComplete1);



PageMethods are currently not supported inside user controls. I've open a bug to track that issue. Thanks.

If I put the WebMethod in the calling page I can call it from the usercontrol, which allows for the functionality that I desire. This is not as clean as I hoped for but it will work.


Has this been fixed in the December release? It appears not, unless I am doing something incorrect. I am getting the js error 'Web' is undefined. Even my work around for this problem apears to be broken.

No comments:

Post a Comment