I'm creating an asp.net web application.
In the web application I have a web service.
I added [System.Web.Script.Services.ScriptService]
To the web service file and added a script manager to the aspx page.
When I call the web service in javascript I get an e开发者_开发知识库rror "Microsoft JScript runtime error: 'getText' is undefined"
This same code works in another project, but it's a website project and not a web application. Maybe there is a difference between the two in this respect?
Thank you! -Elad
What are you trying to do with getText ? Is this a valid ASP.NET AJAX command?
Assuming it is...
Not much info to go on here, but make sure you have added a reference to the .asmx file of your service on the <ScriptManager>
control in your page.
You can do this in markup, or in code like this (usually during the Page Load event):
sm.Services.Add(New ServiceReference("~/YourWebService.asmx"))
Where sm is the id of your ScriptManager.
Also, if the JavaScript file you're using to call your web service is external, load it by registering it with the ScriptManager like this rather than adding a reference to it in your markup:
sm.Scripts.Add(New ScriptReference("YourJavaScriptFile.js"))
This ensures it won't run until the ScriptManager is ready.
Also, add this line to the very end of your JavaScript file:
if (typeof (Sys) !== 'undefined') {Sys.Application.notifyScriptLoaded(); }
This notifys the ScriptManager that your JavaScript file has loaded.
I switched from a web application project to a web site project and everything started working. I don't really know why this is, but it just worked.
精彩评论