asp.net ajax not working - asp.net

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 error "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.

Related

Why do we use 'code behind' in WCF?

First of all, what are the advantages of Code Behind and Code Beside? I have searched on the internet and found that we use Code Beside in web sites and in ASP and Code Behind while creating WCF. What is the reason behind this?
Thanks in advance
Because WCF service is not a web page. In ASP.NET WebForms you define markup in your web page and code related to markup. When the page is compiled initialization code related to markup is generated and merged with your code to form a single class handling the web page.
In WCF the "markup" contains just declarations. It is just support file for IIS processing which will tell web server which service factory and service type must be used to handle incoming call. Information from markup is not related to your service class and there is no code merge - the code behind service class is complete implementation of the service and can be used even without the markup file which is not true for code beside web pages.

Adding a stand alone ASPX page to an existing web application (.Net 3.5)

I downloaded the file discussed in this article and tried "dropping it into" a production web site, but got the following error when I tried to access it through my Web browser:
[HttpException (0x80004005): The file '/WebResources.aspx' has not been pre-compiled, and cannot be requested.]
If I drop the file into webs on my local machine, it runs fine. How do I pre-compile this single file without re-publishing the whole application? Is there something that I can do to pre-compile just this one page. (Note: It doesn't reference any external controls, Masterpages, etc.)
One lazy solution for your problem (without checking the source of the error) is to view the page inside an iFrame.
<iframe src="/WebResource.aspx" width="100%" height="100%">Your browser does not support iFrame</iframe>
but if you need that page to interact with controls outside of its scope, then you will need to look into the header part of the ASPX and make sure that it inherits from the proper class, and is part of the Web Project that is calling the page.
This is pretty easy to do.
Put the file into it's own web application project.
Publish the project to a local directory.
Copy the file and associated assembly to your existing web application. Take care NOT to overwrite your web.config.
Done. This new file now has access to everything your other web app does.

How to use AJAX Control Toolkit client-side functionality without IIS

I ran an ASP.NET page that i have under development on my local IIS. It uses some dragPanelExtenders as well as some other AJAX Control Toolkit AJAX client side stuff, and in order to show the page to somebody, I wanted to put it up as a plain HTML file, hosted on a live web server (running APACHE). (This is the only public web server I have access to, and I want them to be able to drag some panels and experience the page as it would be when "live")
So, I viewed the page running on my local IIS, then saved the source as a HTML file.
Then copied this HTML file to the web server ( as well as necessary CSS, JS and image files).
When I view this HTML file through the web server, I get this error :
ASP.NET Ajax client-side framework failed to load.
By debugging, I see that the following lines were in my saved HTML :
<script src="/Insata10/WebResource.axd?d=VAXZudqFsChpNfB" type="text/javascript">
<script src="/Insata10/ScriptResource.axd?d=Dwbyv-OIp-kJQdqf_UMh7wUzi2" type="text/javascript">
<script type="text/javascript">
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
So, at runtime, the referenced resources "ScriptResource.axd" and "WebResource.axd" were not found.
Is there any way to get whatever is needed from those AXD's to my HTML file, without actually executing anything on IIS?
Not easily. The Ajax Control Toolkit relies on server-side .NET Code, which runs in the context of IIS.
You can us a different web server, such as the Cassini web server that comes with Visual Studio (or write your own), but I expect that you're looking for a simpler solution, and none exist for what you're asking.
The bottom line is, the server-side code needs to run, and for that you need a server. You can't just open the file and have it work.
The best you could do would be to find similar javascript to get the desired funcitonality.
edit
I'm always forgetting about Mono, so if your Apache server is set up and configured correctly, you CAN run .NET code from an Apache server. http://www.mono-project.com/ASP.NET
Still not simple, though, so my answer of "not easily" does not change.

Asp.net .ashx error in sharepoint

I am trying to shift my asp.net 3.5 application (C#) to sharepoint.
I have used one .ashx(web handler) file for multiple file upload control in my application
Now it works perfectly locally in asp.net but when i do the same thing with sharepoint with no change in code it stops working.
I dont know if i need to add some dll or any supportive file to get that file upload page (using .ashx file) working in sharepoint
Please help
Your are not adding your handler to sharepoint's web.config ...
like
see my post for what i did to make it work Custom Httphandler in SharePoint

ASP.NET Ajax: 'PageMethods is undefined' script error on production server (works on localhost)

In a javascript file I'm calling an ASP.NET Ajax PageMethod (ASP.NET 3.5), correctly defined in the page class a static method using the WebMethod attribute. This works on my development machine, but on the production server the PageMethod object is undefined when my javascript function is called (clicking a button).
Some debugging info:
Error on Firefox and Internet Explorer
According to Firebug's network tab all external resources are correctly loaded
I'm using jQuery on the same page
The application is deployed using a Web Deployment project
Any idea what's causing the problem?
I found the solution to the problem after having written the question. I'm doing a dirty trick in order to avoid copying the aspx placeholder files (Web Deployment Project) to the server: in IIS I've unchecked the .aspx ISAPI extension option "Verify that file exists".
That seems to be a problem for ASP.NET Ajax. So I created an empty aspx placeholder file and ... now it's working on the production server too. I'll put a warning sign on the question/answer I linked above.

Resources