手动实现UpdatePanel
我正在阅读一篇文章,其中显示 CodePlex 使用 UpdatePanels 有多糟糕,而 StackOverflow 在这个问题上有多好,例如,当用户对答案/问题进行投票时。
我想知道是否有人可以指出如何执行此类操作的教程。
我知道一些要点:
- 创建一个获取操作值并输出 JSON 字符串的 Web 服务
- 在
控件内构建 javascript,以用新值替换页面上的正确值
但是,即使在第一次我遇到困难,我可以发送一个 JSON 字符串,但它总是会被 XML 信息包围!
任何人(或者杰夫)都可以从头开始指出一个很好的“操作方法”吗? 谢谢。
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:
- Create a Web Service that gets the action value and ouputs a JSON string
- Build the javascript inside
<ajax:ScripManager>
control to replace the correct 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我怀疑
StackOverflow
使用UpdatePanel
- 更有可能它使用 jQuery / load 来简单地更新 div,使用 ASP.NET MVC 作为源(而不是 ASP.NET vanilla,后者具有更复杂的页面周期)。使用这种方法,一切都很简单……jQuery 示例选项卡很大程度上说明了一切。
重新返回 Json - 这只是从 ASP.NET MVC 中的控制器
return Json(obj);
- 但我个人会返回 html (更简单)。Well, I doubt
StackOverflow
usesUpdatePanel
- 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).在您关闭 UpdatePanel 之前,我建议您阅读我写的这篇文章 - http://www.aaron-powell.com/blog/august-2008/optimising-updatepanels.aspx。 它着眼于如何优化 UpdatePanel,如果做得好,可以带来一些性能提升。
我还发表了一篇文章 - http:// www.aaron-powell.com/blog/august-2008/paging-data-client-side.aspx 它着眼于使用 jQuery 和 MS AJAX 进行客户端模板化。 我将了解如何使用 JavaScript 读取 Web 服务,如果您下载示例,您将了解如何将数据客户端发送到 Web 服务。
但是 ASP.NET 网站上的这段视频也可能有用 - http://www.asp.net/learn/ajax-videos/video-82.aspx。 它是关于如何扩展 Web 服务的脚本服务功能。
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.