views:

58

answers:

4

I consider myself very knowledgeable in web UI development, and over the last four years I have learned a lot about ASP.Net Web Forms, but I still haven't figured out a good way to update sections of a page via Ajax. I have done this several different ways which basically involves a user control loaded by some sort of .aspx page or handler. This works well, but not very generically and usually runs into ViewState issues with anything that is even moderately complex.

I would have jumped to UpdatePanel's sooner, but Microsoft's JavaScript code is total crap. Does anyone have any good strategies to load/update/refresh sections of a web form without using UpdatePanels? Or does anyone have any tips with using UpdatePanels to get around some of the front-end code crappy-ness?

Update (clarification)

Here is an example situation of what I am trying to do to be more clear. On our homepage near the bottom of the page we have some tabs with different content. Each tab's content body has different content geared to some different user type. Of the thousands of homepage visitors we get a day maybe a dozen click on any tab. Despite this data our managers still would like to have the tabs there. Because each tab body has a lot of HTML content in it, I want to load the content of the tab when the tab is clicked. The solution is obviously to use ajax; however, where do you put the HTML/Controls to load the HTML when the tab is clicked. I could put each tab's content in its own apsx page (e.g./home/tabs1.aspx), but then we couldn't easily embed the content in the page initially if we wanted to. I could put the content in its own user control and create a HttpHandler or page that loads it, but this leads to view state issues on more complex pages. I could just hard-code the HTML in a function and then set it a literal or return the HTML in a handler when an ajax request calls it. Each of these solutions work. Some are more ideal than others (the third one is terrible separation of concerns, although I have seen it before). UpdatePanel's provide the best solution thought because they let you put the content in the correct part of the markup with out a separate file. The problem I have with UpdatePanel's is they require you to use Microsoft's javascript library. Are there any solutions that work like UpdatePanel's without using UpdatePanels?

A couple of other use cases, I am trying to solve:

  • Box on page that has content when loaded, but updates every 30 seconds
  • Big masthead navigation menu's that I would like to load only when a user hovers over a section
  • You have a form that displays in a lightbox when a user click's a link. (this can cause viewstate issues)
+1  A: 

JQuery seems to be the most popular way to go... http://docs.jquery.com/Downloading_jQuery

o6tech
jQuery is just a library that has a wrapper XHR object for different browsers. It does not help with how you would actually architect and payload the content of a page you want to update. This scenario is fairly easy with other web frameworks (e.g. Rails), but because Web Forms uses controls and viewstate it is hard to create a generic method to lazy load content or refresh content with out causing issues.
howardr
Ahh, I misunderstood the question (read it too fast I guess). I still live in a WebForms world, but from what I read it seems like the issues you've mentioned are why many people are moving over to ASP.NET MVC.
o6tech
@howardr: if you're only interested in solutions that work with `WebControls` (and solutions that provide data which will survive postbacks), you should edit your question to make that clear. A sample usage scenario would also help us answer you.
Jeff Sternal
@Jeff: I tried clarifying my post. Let me know if that helps@o6tech: yeah, oh how I wish I could switch to MVC. This solution is much easier with that framework (or rails, php, any modern framework)
howardr
+2  A: 

There are specialized scenarios where you can accomplish asynchronous page updates with less of a request/response payload than caused by UpdatePanels.

For example, the AjaxControlToolkit provides several components that can update through a non-UpdatePanel asynchronous callback. For example, the CascadingDropDown control extender facilitates scenarios where one drop down should be filtered based on a value in another dropdown. Instead of wrapping up the whole form in an UpdatePanel, the lightweight extenders provide the benefit.

It's difficult to suggest a blanket approach, though, as each AJAX scenario might involve different controls, extenders, or JavaScript libraries (such as JQuery).

kbrimington
Thanks for the link. Those controls definitely will help me from reinventing the wheel for certain functionality. Those controls though do not help my particular issue. I added some clarification to my question if that helps. I am afraid though that there is no blanket approach, and that each case needs to be addressed separately.
howardr
+1  A: 

I guess this article by Mr. Jeff Prosise will be of help to you and all those who are new to AJAX(it did me pretty good):

UpdatePanel Tips and Tricks

Anchit
A: 

ditch web forms, switch to MVC :) you won't regret it. there is a bit of a learning curve, but if your familier with classic asp it's not so bad.

mvc combined with a powerful javascript library makes for very powerful (and easy) dynamic web apps.

Patricia