views:

123

answers:

7

1) A while ago I’ve started learning Asp.Net, but then I’ve heard that Ajax is “the new thing”. Since I don’t want to throw away the time I’ve invested into Asp.Net, I’d like to know if it is a common/recommended practice to use both technologies ( Asp.Net and Ajax) when creating websites and web apps in general?

2) If it indeed is a common practice to use the two technologies together, is that only true for server-side Ajax and Asp.Net or can client-side Ajax also be used in conjunction with Asp.Net?

thanx

EDIT:

A)

The only problem is that it can be a bit trickery to do ajax request using jquery when using asp.net webforms(asp.net mvc was designed with frameworks like jquery in mind so it is easier to do).

Are you implying that perhaps jquery could be too much of a hassle when used together with webforms and thus I should think of using Asp.Net Ajax instead?

B) Little I read on ajax is that it also needs to call web services or some other technology that provides similar functionality to web services. If true, which technology do you use ( WCF or Asp.Net web services or … )?

C) Is Ajax a subsection of jquery? Thus, to understand Ajax, will I need to purchase only a book on jquery or will I also need to read a book with Ajax in its title?

+5  A: 

You can use both, and it is common to use both. MS has a toolkit around using AJAX on asp.net sites:

http://www.asp.net/ajax/

David
+2  A: 

Ajax is a methodology which can be used in conjunction with with other frameworks, such as asp.net. Asp.net will allow you to integrate javascript to implement ajax solutions. A common implementation is to use javascript to call an asp.net webservice to perform ajax operations.

derek
+4  A: 

1) Yes it is common to use Ajax and Asp.net on the same website. I do it all the time(in fact if you turn off javascript on my sites they won't work too well as so much is AJAX). AJAX allows for requests to the server to be made without refreshing the page you still need a serverside language to do stuff with that request. You also need the load the page for the first time so asp.net controls still are needed and in fact if your using asp.net ajax then you can use update panels where you put controls into that automatically become ajax enabled.

2) I am not sure what you mean but Ajax is mostly javascript so it lives on the client side and sends requests to the server side.

Edit

Ok I skimmed most of the stuff in those chapters. AJAX server side is where most of the rendering is done on the server side. So the update panel is an ajax server side control. You drag it on to your webform throw some other server side controls into it and a button. If a user then clicks on that button in the update panel an ajax request is made to the server and you can grab all the stuff you need and use C# to change it. You never have to write one line of javascript code to make that happen.

Of course that has a price though for instance an update panel does not do a true ajax request because of the page life cycle. If you actually watch the code through the debugger you will notice it will go through the page life cycle but in the end will just rerender that update panel so there is a bit more over head then if you did it yourself.

Client side Ajax is basically Microsoft trying to make it easier for you to do javascript by trying to make it more like C# syntax and giving you built in methods. A problem is that alot of people throw the buzz word Ajax too often around and call stuff that should not be called Ajax when it should be just called javascript.

This seems to be the case with this client side ajax as most of what I seen in the client side ajax chapter is almost all javascript. Like in "Figure 33.8. Selecting a menu item." all it seems to be is your click on a choose then it displays the name of that button that is not really Ajax.

Ajax to me is when you actually make a server request to post or get some information with out the page refreshing(ie full post back). For example if you got a form of data that you want to send to the server to be saved in a database. If you would hit the save button and that form data would be sent to the server without the page refreshing then that would be an Ajax request.

Most of the stuff in the ajax tool kit is more javascript

http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Calendar/Calendar.aspx

For instance the calendar control to make it select different dates it is not doing any sort of request to the server since it is all javascript so why would it be ajax if it never posts to the server?

If you would take the value in the textbox that the calendar control puts the date in and post it to the server without refreshing the page that would be an Ajax request.

Finally I would not be too worried about asp.net webforms going anywhere anytime soon. I believe the guy who wrote that article about asp.net going to dye is the guy who made Ajax or was involved some how with the development of Ajax so he is probably biased.

Besides look its been 5 years now since he posted that and asp.net is stronger then ever. Ajax still needs a server to connect to, you still need to render the initial page load with either straight html or asp.net server controls.

Edit 2

1) Yes I think jquery is better the MS ajax for a couple reasons:

  1. It uses less resources then drag and drop controls
  2. It simplifies javascript alot as it makes it easier to use(such as selecting html controls,etc). So if I was using MS ajax I probably still be using jquery for the selectors it has so it is kinda redundant to use both unless you have a good reason too.

The only problem is that it can be a bit trickery to do ajax request using jquery when using asp.net webforms(asp.net mvc was designed with frameworks like jquery in mind so it is easier to do).

2) You really only need to learn jquery and not even javascript. I read a javascript book in like a day then jumped into jquery without even doing on exercise in the book and never did javascript before and I had no problem doing jquery. Of course if you got javascript experience it is a plus since sometimes you will be trying to find a jquery solution when javascript already has a method for what you want to do.

Edit 3

A)

The only problem is that it can be a bit trickery to do ajax request using jquery when using asp.net webforms(asp.net mvc was designed with frameworks like jquery in mind so it is easier to do).

Are you implying that perhaps jquery could be too much of a hassle when used together with webforms and thus I should think of using Asp.Net Ajax instead?

No I am not implying that it is too much hassle for webforms was just stating the fact that it will be a bit more tricky in certain situations then ms ajax and jquery with say asp.net mvc.

asp.net webforms was not really made for a framework like jquery and has trouble dealing with it because of it's page life cycle gets in the way. MS ajax might have it's own set of challenges though too(like everything usually does). Jquery was made in mind of to try and work across all browsers since in javascript many times you would write something that worked in IE but did not work in any other browser and I am not sure if MS ajax client side version thought about this.

B) Little I read on ajax is that it also needs to call web services or some other technology that provides similar functionality to web services. If true, which technology do you use ( WCF or Asp.Net web services or … )?

Yes this is true. This was the whole point many people including me where trying to make to prove that guy was wrong that asp.net was dying because of ajax, since you need something in the back end to make a call too.

However you can choose whatever you want. You can make a separate web service( can be a asp.net web service), you can have like static web service methods in your page load ( I never done this way) and the way I use to do it is by making a generic ajax handler.

You can't however just make a regular method in your page_load and try to call it as it has to go through the entire page life cycle.

http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

http://weblogs.asp.net/craigshoemaker/archive/2008/11/07/using-jquery-to-call-asp-net-ajax-page-methods-by-example.aspx

http://dotnetslackers.com/articles/ajax/using-jquery-with-asp-net.aspx

http://sites.google.com/site/spyderhoodcommunity/tech-stuff/usingjqueryinaspnetappswithhttphandlersashx

I have not read these tutorials but these tutorials should show you the 3 different ways you can do an ajax request to an asp.net webservice, asp.net code behind page and asp.net generic handler.

Choose what ever one you think is best. I don't know if one way is better then another and there probably are more ways to do it.

C) Is Ajax a subsection of jquery? Thus, to understand Ajax, will I need to purchase only a book on jquery or will I also need to read a book with Ajax in its title

Ajax is just part of jquery and probably won't take you long to learn. If you buy a book about jquery there will probably be like 1 chapter on it. The only down side is all the jquery books I know of are all in php.

So if your just buying it to learn the ajax part probably not worth it since they will show an entire example of how to do it with php that might be slightly different then if you did it with asp.net( mostly just setting up the server side to accept the jquery calls- see the links that I posted above).

If you want to learn jquery selectors and stuff then it does matter if the one chapter is in php since it's all client side stuff expect for the ajax part( what is client side and server side).

It's not hard to really do the ajax stuff it just knowing what path you need to choose and more how to accept stuff on the server side and return stuff from the server side.

$.post("test.php", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });

The above is basically all you need to do on jquery side to send some ajax stuff. The first parameter is the path where this request should go. In this case its some php file called test. The next parameter is the the actual data sent as a json result and finally the last line is the function call back line. When the ajax post request is done that line gets called and does the actions. Data is the returned stuff you sent back from the server.

http://api.jquery.com/jQuery.post/

So I would just go through the tutorials I posted and play around with the jquery selectors. Once you done that you can decide if you want to go with jquery or not. The last thing I wanted to point out about why I like jquery is the fact that if you learn the MS ajax stuff your basically stuck with asp.net( what I have no problem with since I love .Net) but with jquery you can easily take your code or those skills of jquery and use it with php, ruby or whatever else and all the client side jquery selectors won't change by switching a different language. The only thing that will be different is the ajax stuff and even that won't be 100% different as the jquery ajax client side could will be the same.

chobo2
“ I am not sure what you mean but Ajax is mostly javascript so it lives on the client side and sends requests to the server side.”I’ve read that Microsoft offers server-side Ajax framework and client-side AJAX framework, so I assumed that perhaps only server-side AJAX framework could work with asp.net
AspOnMyNet
Well I don't know too much about MS ajax framework as I use jquery for all my Ajax needs with asp.net. It could be that the AJAX server side is like drag and drop controls that get rendered on the server side but to make it actually work there is tons of javascript code. I will look more into it. I only used the MS Ajax stuff once and that was like 3 years ago and some of the stuff they called AJAX is sometimes stuff I would not classify as AJAX. If you got a link to where you read this that would be helpful.
chobo2
“If you got a link to where you read this that would be helpful”It’s from the book Asp.Net 3.5 unleashed
AspOnMyNet
What page is it on?
chobo2
check my edit in the above post.
chobo2
"What page is it on?" It's on page 1600, but since you've asked this over an hour ago, I guess you've already found it out. i apologize, but I wasn't online so I didn't notice your question sooner. In any case, from your reply it seems that if I plan to learn AJAX ( even if I want to use it in conjunction with Asp.Net ), that I should avoid both Microsoft client-side and Microsoft server-side AJAX ( which is called Asp.Net AJAX ) and should instead learn some other Ajax technology? But which one?
AspOnMyNet
Well it's up to you I am sure MS stuff is good. For me it was sort of a life saver. When I was learning asp.net and C# I did not want to learn about javascript and ajax as it would be just to over whelming to learn all at once but at the same time I wanted to give my sites that functionality that javascript and ajax brought. So it was very helpful in the beginning for me. I don't use it anymore since I moved onto a javascript framework called jquery(MS has put their full support behind the people making this framework). It makes javascript so much easier to do, has ajax and tons of plugins...
chobo2
That you won't need to make many things that you need as there are usually 10 versions of something that you want(for instance if you want a date picker or javascript tabs).
chobo2
Ok, deciding what path to take with regards to ajax is an important decision, since it may take months of my life, so it deserves a thread of its own, but still it won’t hurt if I ask you here:1) in your opinion, is jquery better than Microsoft’s Ajax, even if we’re using it in Asp.Net application? 2) I assume if I decide to learn jquery, all I will need to learn is javascript and jquery library, or is there some other techmology I’ll also need to learn?
AspOnMyNet
See my new edit.
chobo2
I've edited my initial post ... I know I'm testing your patience, but could you help me with the questions in the post I edited?
AspOnMyNet
"However you can choose whatever you want. You can make a separate web service( can be a asp.net web service)"What about WCF?Anyways, I really appreciate your help
AspOnMyNet
I don't really know what that is so I cannot comment on it. However doing a quick search it seems like you can use it with jquery ajax.
chobo2
It's abbreviation for windows communication foundation.Anyways, thank you all for helping me out
AspOnMyNet
No problem. Good luck!
chobo2
+1  A: 

AJAX is a technique essentially added on top of an existing website to allow things to be done on that page without refreshing the entire page. Here on StackOverflow, for example, you can vote by clicking the up/down arrows via AJAX, without the page refresh you'd have seen without AJAX.

It doesn't replace ASP.NET (or any other language).

ceejayoz
“It doesn't replace ASP.NET (or any other language).” That’s what I’m hoping, but in book Asp.Net 3.5 unleashed author says the following:“Microsoft ASP.NET is a dying technology. It received itsdeath blow on February 18, 2005 when Jesse James Garrettpublished his article “Ajax: A New Approach to WebApplications.” All that is left is the long, slow goodbye.”
AspOnMyNet
It's not dying because of AJAX. It's dying because of things like ASP.NET MVC http://www.asp.net/mVC/
ceejayoz
Ya I agree with ceejayoz ajax is not going to kill asp.net as you need some sort of server language in the first to make AJAX useful. If you make an ajax request and you got no server language what is it going to return? Ajax complements asp.net, like I still need asp.net to load up the page for the first time but ajax makes it so everytime I submit some data to the server the user does not need to see the page being refreshed making a nicer user experience and saving resources but you still need some sort of server language to handle the ajax requests.
chobo2
That author doesn't seem to be offering a very useful opinion there - the problems of ASP.Net WebForms development are NOT related to AJAX, but to the WebForm page lifecycle abstraction.
Tetsujin no Oni
+1  A: 

AJAX does not replace ASP.NET. They can be used together or independently. ASP.NET is more of a framework, where AJAX is a set of techniques built on top of JavaScript and HTML.

There is a framework that Microsoft has called ASP.NET AJAX. There are controls that will output JavaScript so that if you wish, you can have AJAX functionality without having to get too far into JavaScript.

However, you could also write the JavaScript by hand and use XMLHttpRequests to send requests to ASP.NET URLs and get data back.

David Hogue
A) “There is a framework that Microsoft has called ASP.NET AJAX.”I assume ASP.NET AJAX is official name for server-side AJAX framework? B) “However, you could also write the JavaScript by hand and use XMLHttpRequests to send requests to ASP.NET URLs and get data back.”I assume this approach is done by using Microsoft client-side AJAX framework?
AspOnMyNet
A) ASP.NET AJAX is basically server side controls that generate JavaScript + a set of JavaScript libraries. The only code you'd need to write is on the server side.B) You can also write client side JavaScript that will load content from a URL. This URL could be a .aspx page that returns XML or something, it does not necessarily have to know anything about AJAX or JavaScript. There are really a lot of ways to go about this.
David Hogue
“You can also write client side JavaScript that will load content from a URL”Would you recommend an Asp.Net developer to learn ASP.NET AJAX (ie server side AJAX), or would it be better ( in the long run ) if I learn the client-side AJAX, even if the learning curve is a bit steeper or would you perhaps recommend something completely different(like jquery or...)?
AspOnMyNet
Personally, I like to know what is going on so I tried to get at least a basic understanding of how the AJAX techniques worked. The ASP.NET AJAX was a little too abstract for me, it's probably great if you need to get something going fast or if you are creating reusable controls for developers. jQuery is nice and makes developing the client-side scripts easier, it even has some functions that will deal getting cross-browser XMLHttpRequests working without much hassle (http://api.jquery.com/category/ajax/)
David Hogue
So I should prefer jquery over Microsoft's ajax even when working with asp.net apps?
AspOnMyNet
It's mostly personal preference. I find jQuery simple and easy so that's usually what I start with. Plus Microsoft is shipping it with Visual Studio these days: http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx
David Hogue
+1  A: 

ASP.Net is primarily a server-side technology stack which dynamically generates most of the client-side code. The out-of-the-box ASP.Net 2.0 page model is a fairly painful way to implement AJAX-enhanced user interaction (though there are techniques, such as custom handlers, that make it pretty tractable). Both the ASP.Net MVC and ASP.Net AJAX frameworks provide helpful tools for making it lest troublesome.

AJAX is commonly used to describe any asynchronous, partial-page-interaction technique to build the user interface of your application.

The server-side technology and the client side technology choices are fairly independent, though different techniques for how to work with a client side technology become attractive with different frameworks on the server.

Tetsujin no Oni
“The out-of-the-box ASP.Net 2.0 page model is a fairly painful way to implement AJAX-enhanced user interaction … ASP.Net AJAX frameworks provide helpful tools for making it lest troublesome.” Is ASP.NET AJAX official name for Microsoft server-side AJAX framework? If so, are you then implying that combining Asp.Net and AJAX using client-side AJAX framework can be problematic?
AspOnMyNet
No, ASP.Net AJAX was an additional component bolt-on to ASP.Net 2.0 in the post-VS2005 timeframe. Using only ASP.Net 2.0 and client-side ajax can be a pain for developers who are only familiar with the ASP.Net 2.0 WebForm style request/response lifecycle.
Tetsujin no Oni
“Using only ASP.Net 2.0 and client-side ajax can be a pain for developers who are only familiar with the ASP.Net 2.0 WebForm style request/response lifecycle”Would you recommend an Asp.Net developer to learn ASP.NET AJAX (ie server side AJAX), or would it be better ( in the long run ) if I learn the client-side AJAX, even if the learning curve is a bit steeper or would you perhaps recommend something completely different(like jquery or...)?
AspOnMyNet
+2  A: 

Ajax is the new "old thing" - ASP.NET MVC is the new "new thing" :-)

But seriously, you can mix all of these technologies in one web application if you want:

M4N
mvc isn't new, only MS version of it is :)
David