开发者

Is there a better way to update content via ajax in ASP.Net web forms thanUpdatePanels?

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 retu开发者_Python百科rn 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)


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).


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜