Using AJAX methods from a widget (UserControl)
Hi,
I want to add a bit of AJAX magic to one of my pages. Just call a server-side method from JS, and get the result.
This turns out to be more difficult than expected.
First, I found out I can't have AJAX methods in a UserControl (http://stackoverflow.com/questions/5818265/pagemethods-is-not-defined), as I work with UserControls (ascx) rather than Pages (aspx), since the result is supposed to be a widget added to the Sitefinity Toolbox.
From what I read, I have to create and use a web service to be able to achieve that (I'm not too happy about this, this is unneeded complexity, but oh well).
So, I followed the steps of this article: http://msdn.microsoft.com/en-us/magazine/cc163499.aspx
And now, after doing everything detailed in this article, I hit the following JS error as I call my AJAX method:
q is not a function coming from line 3345 of Telerik.Sitefinity.Resources.Scripts.MicrosoftAjax.debug.js
This is my JS code:
Namespace.Class.HelloWorld(
"test"
, onComplete, onFailure);
function
onComplete(result)
alert(result);
function
onFailure(result)
alert(
"Error: "
+ result.get_message());
using
System.ComponentModel;
using
System.Web.Script.Services;
using
System.Web.Services;
namespace
Namespace
[WebService(Namespace =
"http://tempuri.org/"
)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(
false
)]
[ScriptService]
public
class
Class : System.Web.Services.WebService
[WebMethod]
public
string
HelloWorld()
return
"Hello World"
;
<
asp:ScriptManager
ID
=
"scriptManager"
runat
=
"server"
>
<
Services
>
<
asp:ServiceReference
Path
=
"~/Namespace/Class.asmx"
/>
</
Services
>
</
asp:ScriptManager
>
I managed to get it working.
The problem was that I passed a param on the JS side (the "test" string), while the server-side method doesn't expect a parameter. So this works either by removing the "test" param in the JS, or by making it so the HelloWorld method expects a string parameter.
I'd still appreciate an answer to my last question.
Thanks.
Hi Thomas,
The .pdb files are added only in debug. There is no Sitefinity specific setting concerning generation of debug databases. I have tested disabling debug and no .pdb was generated.
<
compilation
debug
=
"false"
targetFramework
=
"4.0"
>