views:

238

answers:

2

I was reading an article that shows how bad CodePlex uses UpdatePanels and how nice is StackOverflow on this matter when, for example, a user upvotes an answer/question.

I wonder if someone can point a tutorial on how to do such action.

I know some points:

  1. Create a Web Service that gets the action value and ouputs a JSON string
  2. Build the javascript inside < ajax:ScripManager > control to replace the currect value on the page with the new value

But, even in the first I have difficulties, I can send a JSON string, but it will always be surrounded with XML information!

Can anyone (or maybe Jeff) point to a nice "how-to" since scratch? Thank you.

+3  A: 

Well, I doubt StackOverflow uses UpdatePanel - more likely it uses jQuery / load to simply update a div, using ASP.NET MVC as the source (rather than ASP.NET vanilla, which has a more complex page cycle).

With this approach, it is trivial... the jQuery examples tab largely says it all.

Re returning the Json - that is simply return Json(obj); from the controller in ASP.NET MVC - but personally I'd return the html (simpler).

Marc Gravell
+2  A: 

Before you dismiss the UpdatePanel I suggest you have a read of this post I did - http://www.aaron-powell.com/blog/august-2008/optimising-updatepanels.aspx. It looks at how to optimise UpdatePanels and it can lead to some performance increases if done well.

I also did a post - http://www.aaron-powell.com/blog/august-2008/paging-data-client-side.aspx which looks at doing client-side templating with jQuery and MS AJAX. I look at how to read a web service with JavaScript and if you download the sample you'll see how to send data client-side to a web service.

But this video cast on the ASP.NET website may also be of use - http://www.asp.net/learn/ajax-videos/video-82.aspx. It's on how to extend web services for script service capabilities.

Slace