Concerns when using ScriptManager for Custom Non-Ajax Scripts - asp.net

I have an application that uses various script files. These files are not used for any AJAX purposes. However, I am using MS AJAX Libraries. My goal is to use the ScriptManager to manage release and debug versions of my JavaScript. Is this the right approach? Is there a better way to handle this task?

I found that there is some additional overhead when you are using the ScriptManager. After doing some reading it looks like the ScriptManager control should only be used if you plan on sending down the AJAX library otherwise it would be advised to use the ClientScriptManager.

Related

Framework Similar to ASP.Net AjaxPro

Currently, I'm using AjaxPro Framework (http://www.ajaxpro.info/) to call any methods in my web application from the client side.
But users have some serious problems using it. (e.g success callbacks don't work in Chrome. More info about the problems could be found at: AjaxPro is working locally, but on server I am getting .ashx errors)
I'd like to replace it with a framework that can:
Call any method in my code behind. Even if it's defined in a class library. In AjaxPro I could define a method anywhere and add [AjaxPro.AjaxMethod] attribute to it. Now the method could be called in any client-side js code, even if they were in two different classes.
Doen's depend on web forms. I could replace AjaxPro with ASP.Net Ajax by using ScriptManager and Add [WebMethod] attribute to my methods and call any other method in my solution from that page method. But I'm using .ascx files and Page methods cannot be defined in .ascx files (They have to be defined in .aspx web forms).
Preferably free. (I'd like to use it in YetAnotherForum project development). But if only a paid framework is available, I'll be glad to pay for it.
Is there any other Ajax framework which has the AjaxPro functionality?
I would recommend using jQuery. It is becoming the client javascript API to use. Even Microsoft seems to be inclining towards it in favor of their AJAX client side APIs. You can call any method in a page using the .ajax method, sample here. I have never tried it inside a UserControl, but as long as the method is decorated with a WebMethod attribute, I don't see why it wouldn't work.
I believe you have a fair choice.
Look at http://ajaxpatterns.org/DotNet_Ajax_Frameworks#Lists
At my new job we're using ajaxpro, however I also have come across issues and am currently researching alternatives.

ASP.NET: RegisterClientScriptInclude

I have a page that calls RegisterClientScriptInclude. For some reason, the script isn't included though. If I change it to RegisterStartupScript or RegisterClientScriptBlock, the script isn't written to the markup either.
Why might this be? Are there certain preconditions that may preclude a client script from being registered?
Are you using Ajax? If you're using MS Ajax, you should be using the ScriptManager.Register....() methods.
If you're using straight webforms, you should be using the ClientScriptManager.Register....() methods.

ASP.Net ScriptManager - Is there a smaller version?

I use the ASP.Net ScriptManager to load the scripts needed for calling WCF services via HTTP/JSON. I am optimizing the total size of my pages (including scripts) and I see that Microsoft's AJAX library is the biggest file that I have at 96KB. Is there anyway that I can get a version of this file with just the features I need loaded?
Or since I already have jquery, should I use that to call my WCF JSON service instead?
Cheers,
Jon
WCF JSON services degrade gracefully down to working as a standard webservice, so you should have no problems using jQuery to post and retrieve data from them. You may lose some of the integration bells and whistles, but as someone who has taken the path you're suggesting, I can say that I don't miss it at all.
The only problem might be if you're using advanced WCF feature like 2 way connections, or guaranteed connections.

jQuery vs ASP.NET Ajax

What are the differences between jQuery and ASP.NET Ajax?
They are very separate things, jQuery is a JavaScript framework that has the ability to do some rudimentary Ajax functionality while ASP.NET Ajax is a more fully-featured Ajax framework that encompasses .NET controls and server-side aspects as well as client-side aspects.
jQuery's main focus is on a creating standard, stable, and powerful framework for working with JavaScript as a whole in the client.
Albeit ASP.NET AJAX encompasses a client side framework it is perhaps best known/feared/loathed for its server side controls, particularly the UpdatePanel. What you get with ASP.NET AJAX is out-of-the-box AJAX for the most basic stuff without having to write a single line of JavaScript.
If on the other hand you need to write some JavaScript or go a little out-of-the-box, working with ASP.NET AJAX can soon become a little tedious.
jQuery on the otherhand is lightweight and requires you to write JavaScript, although for most part, the jQuery guys has done a very good job of hiding the ugly JavaScript stuff away, so apart from a small learning curve it comes pretty natural (particularly if you are on home-stretch in CSS selectors).
Main problem in using jQuery with ASP.NET can be if you mess too much with the DOM you might get ViewState/Event validation problems.
jQuery is a standalone javascript library that can be integrated into any development environment. It it widely used and many great plugins exist for it.
It can be used for much much more than just AJAX functionality. Like traversing through current elements and changing their functionality.
ASP.NET AJAX is something else entirely, since it only focuses on AJAX like functionality in the .NET environment.
Main goal of ASP.NET Ajax is calling ASP.NET web services from client using simple JavaScript notation. It also provides client access to some ASP.NET server features. Like profile, for example. All other operations it's better to perform with jQuery.
i used Ajax Control Toolkit from microsoft quite extensively for 2 years before i switched to jQuery and in my experience i think jquery ajax calls are much more light weight, efficient compared to the ajax control toolkit libraries. besides that the efficiency ofcourse depends on the data that you send & receive via your ajax calls.
you can add custom HTTP Status codes in jQuery ajax calls as well to capture any errors on the server and returning the appropriate response.
#Andrew and #Ólafur hit the nail on the head, but I would add that the biggest concept that separates these two approaches to ajax development is that w/ jQuery you get total control of what happens between the client and the server. With the MS AJAX Toolkit you give up any control over what is sent between these 2 points. If you want to be "close to the metal" you would be best to choose jQuery. If you are just working up some quick and dirty solution that needs zero customization and speedy delivery is all your client cares about, maybe take a look at the MS AJAX Toolkit.
by the way - scott gu officially announced that asp.net would include support for jquery (full intellisense too) with their ajax framework (which is really bloated)
check this link - http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx
if you have used ms ajax, you would be aware its really really bloated up, and many things which ms ajax does - you can achieve via jquery writing few lines of javascript code, and you would save a lot on bandwidth and performance
you can even call asp.net json + xml web services via jquery writing just few lines of code

Should I create a JQuery server control for ASP.net to best use it in my apps?

I have been rather successful in promoting JQuery within my organization. No small feat on it's own. However, one of the ideas being kicked around here to make it part of our app is to create an ASP.net server side control. (We are going to be sticking with WebForms for the foreseeable future.)
I'm not too wild about this approach as it seems like overkill when a couple of script tags will do the job. We found an article on the web, and the amount of code involved really doesn't seem to justify itself. However, I do hear that there is some benefit in the script caching or generating that happens with the server controls.
My questions:
Has anyone else written an ASP.net server control to serve up the JQuery js code?
Does anyone else think that this is a crazy idea to just avoid writing JQuery or Javascript code?
I know Microsoft (along with Nokia) is "mainstreaming" jQuery and will be integrating it with future versions of Visual Studio. You may want to explore how they'll be officially using it so you can tailor your setup now, and hopefully ease your transition to "official MS jQuery" down the road.
I agree with you. It is not worth the time to create and overhead to create a control to make to add a JQuery script location.
A better solution would be to have 1 .js file that has all the links required to load on the page. That could eliminate allot of .js links, if that is the issue with the team.
The only time I would excuse creating a custom control to just link JavaScript would be for whatever reason you did not want to copy the JavaScript to the server and want to be embed it into the .dll. However you will not stop people from seeing the JavaScript on the page because if you embed the files in the .dll you must register them in the header as the full script file.
One reason for using a server control for injecting the JavaScript reference is that it is easier to control which JavaScript files get added to a page. Imagine a scenario where you use jQuery core, plus jQuery UI and a handful of other plugins. Depending on how you coded this control, you could allow a developer to easily choose which features were needed for a specific page without worrying about the specific scripts needed. This approach would allow you lots of flexibility for segmenting your application: for example the server control might be used by a master pages, a child page, user controls or another server control. If the master page registered a requirement for one jQuery library, but the child page or one of the user controls requires additional libraries, then having a unified API makes this simple. Personally, I believe this is best handled by a helper library rather than a server control.
The bottom line is how much you want each developer re-inventing the wheel or using a common, simple to use API which enforces uniformity across your apps.
I found Scott Hanselman's blog post with a sample app that has ASP.net AJAX + JQuery. It's a simple app, but it includes all the javascript with script tags. I don't see any advisement to use a server control to serve up the scripts.

Resources