Update Panel or Ajax calls - c#

I'm doing one app which requires AJAX call on almost every user interaction possible, I started writing JS functions, webservices etc. to handle all of that(still long way to go from here).
Now I am wondering If I made a mistake maybe I should put whole page in update panel because I really hate writting JS. Is there some drawback to use it instead of custom written ajax calls to web service and js functions, and is it better to use more update panels or one big?

The biggest advantage to writing your own is performance. Writing your own JS and webservices is going to be much, much faster.
Microsoft's AJAX UpdatePanels actually re-render the entire page, but then only replace the sections of data that you surrounded with the UpdatePanel tags. When you write your own, you can fully control what happens and when. And if you ever migrate or port your code away from ASP.NET, it's going to be much more reusable.

Absolutely jQuery Ajax.
jQuery AJAX vs. UpdatePanel
http://encosia.com/why-aspnet-ajax-updatepanels-are-dangerous/

Update panel is easier, however it negates almost all the benefits of AJAX because it needs to run through the whole page lifecycle for each postback and loads pretty much the entire page.
Performance-wise manual ajax calls is going to be better.

Another drawback to using update panels is that it is a part of the ASP.NET Ajax Toolkit. The toolkit has been deprecated and is no longer supported.
See this post for more info:
ASP.NET Ajax vs. JQuery for web service calls
The post also contains an interesting blog post about it.

Related

Looking for suggestions on page updates without post backs

So I am working on a personal MVC project for practice. I like the responsiveness with using ajax calls to web services to update the page and not have to do an entire post back.
My knowledge is very limited and I am only aware of being able to do this with Javascript.
However, from a new developer's perspective, there is one problem with this. It would be assumed that you would need to carry out this same behavior through most of your site for any of your CRUD operations on your domain objects. Therefore causing (again for a new developer) the lack of handholding with Javascript (debugging, unit testing, strong type...etc).
But do to my lack of knowledge, is there a way you can acquire this same behavoir in MVC without having to perform all your crud operations with javascript/ajax calls to web services?
NOTE: before beating me up about my loose remarks of Javascript....I like Javascript, and there might be ways to negate some of the points I made with using it for all your CRUD operations to get the behavior I seek that I might just not be aware of.
Based on your question, it sounds like you're looking for an UpdatePanel for MVC. This control isn't valid for ASP.NET MVC, but you could accomplish similar functionality by using AJAX (either the Microsoft.Ajax lib or something like jQuery) and returning a PartialView from your controller. There's a decent tutorial on this technique on Telerik's site (just ignore the parts where they render their own controls -- you could render pretty much anything).
If this doesn't met your needs, the I believe, in order to accomplish an AJAX-like behavior on your page or pages, there will have to be some degree of JavaScript involved.
You may want to consider using a JavaScript framework like jQuery or MooTools in order to wrap the AJAX calling behavior, so that you just have to invoke the already-tested AJAX calls (e.g. jQuery.ajax()). Your JavaScript, then, would just be the callback handlers to update your pages.
On the server side, since you're using MVC (which I'm assuming is ASP.NET MVC), your controllers could just return a JsonResult instead of a ActionResult and just have your CRUD operations inside your controller instead of create a separate suite of web/WCF services. (You could also return an ActionResult to your jQuery.ajax() call, too.)
So I don't think you're going to be able to get away from JavaScript in order to accomplish AJAX-style behavior in your web site. You may not have to create a suite of web services as you could just have them contained within your controller.
This is probably going to get you what you want. You may want to check out a tutorial on the ASP.NET web site for some additional insight (but that won't get you to the unit testing part of your question).

ASP.NET Postbacks x jQuery: What are the cons and pros?

I'll start some lab prototypes on some of our Web App pages. We use a lot of Postback, ViewState, UpdatePanels, ModalPopup Extenders, all the ASP.NET usual stuff. It's good enough for most cases. But I wanna push things further...
I've been playing around with jQuery for some time now. I know what's capable of. I'm thinking of TRULY substituting the ASP.NET usual things by things like $.ajax(), $.get(), etc. No more postbacks. User interface? jQuery UI. I'm truly impressed by some plugins, specially jQuery grid.
I think it's the next step into Web UI. I mean, it's ALREADY the current step! I love the power of C#, but I'm not that impressed with the ASP.NET framework. I imagine that by doing that, I'll truly separate UI from Business logic.
However:
Should I really do it?
Should the code behind be only Web Handlers and Web Services?
What should I beware of?
How about security? How to implement it?
What will I gain? I know I'll gain some in performance, since postbacks in pages with too much data takes time because of the ViewState AND I'll be transacting only XML and/or the always light JSON format. But I imagine, as usual, there will be pain...
Where will the pain be?
I'll take it slow, anyway. But I want to ask you guys: what am I getting into here?
Before I reply, I would strongly suggest that you go for ASP.NET MVC Framework. It's a totally different kind of development than the Webforms. It's a step away from ViewState and that junk. This is where Microsoft is pushing all their efforts to and this is the only way right now to build much more scalable and interactive websites on the .NET Stack.
Should I really do it?
Yes. jQuery + Ajax are very good and would let you build some very interactive and usable websites. And the way things are going right now, truth to speak if you don't use the power of Javascript at the client-side, your website would like build in 1995.
Should the code behind be only Web Handlers and Web Services?
You should only use the handlers/services to improve the design of your page. You can't build your whole website only on that. The method is to create a page, and then improve it with the services. Avoid postbacks for small details. And improve speed by Ajax etc. Making a whole website on Ajax is not a good idea.
What should I beware of?
Technically you need to understand client-side coding and how does HTTP works over the internet. ASP.NET takes does that all under the hood, so you don't even need to know but if you are doing postbacks etc. then you should understand it's limitations etc.
How about security? How to implement it?
There isn't a lot to security in Ajax as long as you do the same stuff which you did for normal postbacks e.g.s CSS attacks, SQL injections, Anti-Forgery etc.
What will I gain? I know I'll gain some in performance, since postbacks in pages with too much data takes time because of the ViewState AND I'll be transacting only XML and/or the always light JSON format. But I imagine, as usual, there will be pain...
Where will the pain be?
The pain usually is the complexity. But complexity comes with flexibility. Traditional ASP.NET was taking care of everything without you having to interfere. but now you have to make up the request, send it to server, receive the reply and then update DOM accordingly. You have to deal with all of that but on the flip side, you can deal it in whatever you want.
Hope that helps.
I say yes. Postbacks are easy for the developer and horrible for the user experience. Don't make them suffer through heavy page loads just to toggle a box on the page.
But, you need to consider the time that it will take, especially since you might have to rely on more and more javascript code (which can be finicky if you are new to it).
I've recently done it on a large project and I'm glad I did it. I moved from full page postbacks to WebMethods and web services. Try to reduce state on the server which will help compartmentalize each request handler.
Look into asp.net-MVC it is most likely what you are talking about and implements jquery and JSON calls.
If you used PostBack and ViewState you might have done that for a reason. It allows for Components and Events. Thats something you will miss in ASP.NET MVC (you dont say you want to use ASP.NET MVC, but if you say ASP.NET without PostBack everyone will understand ASP.NET MVC)
I use ASP.NET and ASP.NET MVC. ASP.NET with postback comes into play if the project is realy more an application than a website (lets say nyt.com being a website and facebook being an application ).

Need some good 'JavaScript for ASP.NET developers' books and blogs, since AJAX UpdatePanels are performance killers

Regarding those articles:
Update Panels and JSON Alternatives
Why ASP.NET AJAX UpdatePanels are dangerous
PageMethods vs UpdatePanels
I think AJAX UpdatePanels can't be the appropriate way of implementing a partial page renders for big application or good scalable ones.
So I hope I could find a dedicated sources for search things.
I know how to integrate JavaScript with ASP.NET
But what I'm looking for is a very specific resource to teach me to do whatever I could have done with AJAX UpdatePanels.
I had a (thankfully brief) affair with UpdatePanels, and since I've started using jQuery http://docs.jquery.com/Tutorials and jQuery UI http://jqueryui.com/
I have never looked back. I know this isnt a book but I found that most of the stuff on the website is pretty well written and can get you started pretty fast :)
I think the idea is you want to start looking to have your client consume server data with as little asp.net heavy handedness as possible.
I think this works alot better in ASP.NET MVC than it did in previous platforms.

Facebook Style "Like" button without postback

How would one go about creating a facebook-style "Like" button in C# ASP.NET without doing a postback? Are there any code examples or tutorials that you know of? I assume that would have to use asynchronous javascript. (this is a tough one to search for due to the Facebook keyword!)
This would have to work with .NET 2.o framework, SQL Server 2005 and VS 2005.
Thanks for any direction.
The technology you are looking for is AJAX. It is a fancy way to use JavaScript (specifically the httprequest object) and the HTML DOM to asynchronously do things on web pages.
Here is a tutorial specific to ASP.NET. It was written for .NET 1.1, but the principles are basically the same.
Suggestion: I really prefer the JQUERY AJAX implementation to the controls that ASP.NET has built in, even when working on ASPX pages. It just seems a lot more lightweight and has less magic going on behind the scenes.
I'm not completely sure what you're asking here but maybe an ASP.NET Web Service would be what you're looking for?
Here are a few links:
http://msdn.microsoft.com/en-us/library/ms972326.aspx
https://web.archive.org/web/20210304124019/https://www.4guysfromrolla.com/articles/062602-1.aspx
http://www.codeproject.com/KB/webservices/aspwebsvr.aspx
Like others said, you need to incorporate AJAX functionality and web services in your page for this to happen. One option is to use Page Methods. Another option is to write wcf services that directly emit JSON[via the ScriptService attribute] and use the callback mechanism to call these services, and handle their response in the success method to update the UI accordingly. Take a look at how to create wcf sercvices for emitting json.

Transitioning from WinForms to AJAX, what do I need to know?

I currently have a functioning in-house Windows Forms application which extensively uses the DataGridView control for data entry. There are some support issues which are expected when we roll this out to more locations, so one of our consultants has recommended putting together an AJAX application with substantially the same functionality.
I have used ASP.NET a bit in the past with the old model where basically everything goes to the server, but I've heard AJAX applications can be made more UI responsive than that.
So my question is, what's the best way to get started with AJAX, for someone who has worked mostly in WinForms C#?
The easiest way, but not neccessarly the best way is to get familiar with the UpdatePanel, which is part of the ASP.net AJAX controls.
You can use an ASP.net GridView control (which shares much of the Winforms equiv. functionality), wrap an UpdatePanel around it and you're away.
Further on from that you will want to get involved with web/wcf services to make calls from javascript to the server and update your UI based on the responce. That of course involved more time, effort and knowledge!
There are many gridview controls you can buy that will help e.g. One from essential objects is nice, not perfect, but very cheap compared to Telerik and other big names.
ASP.net is still a server based technology, but with the inclusion of ASP.net AJAX calls to the server are easy and with jQuery updating the UI is getting easier!!
Hope this helps
What you're wanting to do isn't very hard especially with Telerik's or Infragistic's controls, but as the previous commenter stated, they aren't cheap. They are probably worth the price if you don't want to spend the time rolling your own responsive and editable grid.

Categories

Resources