jQueryMobile在ASP.NET Web窗体 [英] jQueryMobile in ASP.NET WebForm

查看:730
本文介绍了jQueryMobile在ASP.NET Web窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时使用jQueryMobile在ASP.Net Web窗体应用程序中的正确方法?结果什么是ASP.NET Web窗体使用jQueryMobile或其他移动JS库的利弊?

Is using jQueryMobile in ASP.Net Web Form application a right approach?
What are pros and cons of using jQueryMobile or other Mobile JS library in ASP.NET web Form?

推荐答案

ASP.NET Web窗体是一个很好的框架,但你并不需要的大部分为使用JavaScript UI框架的移动开发。我会首先列出利弊,其次是替代并最终给出一些提示,当您必须使用Web窗体尽管利弊。

ASP.NET Web Forms is a fine framework, but you don't need most of it for mobile development with JavaScript UI frameworks. I'll list the cons first, followed by an alternative and finally give some tips when you must use Web Forms despite the cons.

与ASP.NET Web窗体的问题是,你并不总是有在HTML的完全控制。这可以通过<一来减轻href=\"http://weblogs.asp.net/scottgu/archive/2005/12/21/asp-net-2-0-control-adapter-architecture.aspx\">using控制适配器中,通过避免使用某些控件,并且通过使用<一href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx\">EnableViewState在控制和页面属性。 ASP.NET Web窗体4.0还能够减轻一些像<一个问题href=\"http://weblogs.asp.net/scottgu/archive/2010/03/30/cleaner-html-markup-with-asp-net-4-web-forms-client-ids-vs-2010-and-net-4-0-series.aspx\">un$p$pdictable客户端ID 的。但所有这一切确实加起来额外的工作只是为了解决ASP.NET Web窗体的性质。

The problem with ASP.NET Web Forms is that you don't always have full control over the HTML. This can be mitigated by using control adapters, by avoiding the use of certain controls, and by using the EnableViewState properties on controls and pages. ASP.NET Web Forms 4.0 also mitigates some of the issues like unpredictable client IDs. But all of that does add up to extra work just to work around the nature of ASP.NET Web Forms.

此外,大多数Web控件将发出的JavaScript 成为ASP.NET Web窗体页面回传模式工作。例如用&LT; ASP:下拉的AutoPostBack =真正的&GT; &LT; ASP:文本框OnTextChanged =...&GT; &LT; ASP:小组DefaultButton =...&GT; 。这是非常好的,如果你的开发风格主要是服务器端和你开心不与使它成为所有工作的客户端的细节费心。

Also, most web controls will emit JavaScript into the page for the ASP.NET Web Forms post back model to work. For example with <asp:DropDown AutoPostBack="true">, <asp:TextBox OnTextChanged="..." > or <asp:Panel DefaultButton="...">. This is really nice if your development style is mostly server-side and you are happy not to have to bother with the details of making it all work client-side.

&LT; ASP:的UpdatePanel&GT; 是另一个很好的例子:你把它添加到页面中,你已经奇迹般地启用AJAX页面。但它呈现相当大量的JavaScript,所有的视图状态仍然来回发送客户端和服务器之间,甚至一个小小的更新整个页面处理服务器端。

The <asp:UpdatePanel> is another fine example: you add it to the page and you have magically AJAX-enabled the page. But it renders quite a lot of JavaScript, all your view state is still sent back and forth between client and server, and even for a tiny update the complete page is processed server-side.

但是,对于移动开发要优化您的网页小屏幕和快速加载时间。一般来说,移动JavaScript框架采取对客户端的维护状态,发送和异步接收消息和更新通过JavaScript视图的照顾。这意味着,在ASP.NET Web窗体所有的基础设施,在整个后背上保持状态(视图状态,页面生命周期)往往是相当无用的,有时甚至适得其反。

But for mobile development you want to optimize your pages for smaller screens and fast load times. Generally the mobile JavaScript frameworks take care of maintaining state on the client-side, sending and receiving messages asynchronously and updating the view through JavaScript. That means all that infrastructure in ASP.NET Web Forms for maintaining state across post backs (view state, page life cycle) is often quite useless and sometimes even counter-productive.

我觉得整体的ASP.NET MVC是一个更适合一般的移动开发,以及jQuery Mobile的为好。

如果您必须使用ASP.NET Web窗体,然后使用控制,如&LT; ASP:ListView控件&GT; 渲染HTML你是要使用jQuery Mobile的UI列表元素。这种控制使您的HTML相当不错的控制。

If you must use ASP.NET Web Forms, then use controls like the <asp:ListView> for rendering HTML that you are going to use for jQuery Mobile UI list elements. This control gives you quite good control over the HTML.

尽量不要使用&LT; ASP:的UpdatePanel&GT; 控件,因为那时你肯定是混合隐喻。一般情况下,不靠后背上太多。

Try not to use the <asp:UpdatePanel> control, because then you are definitely mixing metaphors. In general, don't rely on post backs too much.

相反,你可以使用Web方法在页面上的你可以从JavaScript直接调用。与 [的WebMethod] 属性静态页面的方法将返回JSON格式的数据,这是一个很好的适合大多数JavaScript框架今天。这些方法事实必须声明为静态手段他们不参加在页面的生命周期。这也意味着它们具有更好的性能特性。

Instead, you can use web methods on your page that you can call directly from JavaScript. Static page methods with the [WebMethod] attribute will return JSON formatted data, which is a nice fit for most JavaScript frameworks today. The fact that these methods must be declared as static means they do not participate in the page's life cycle. That also means they have better performance characteristics.

最后,即使当您使用Web窗体,您可以随时使用.ashx的文件(基本的 IHttpHandler的以及它是异步的表妹,<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ihttpasynchandler.aspx\">IHttpAsyncHandler)或与<一个Web服务href=\"http://msdn.microsoft.com/en-us/library/system.web.script.services.scriptserviceattribute.aspx\">ScriptService属性。这些选项也将迁移罚款,你应该决定使用ASP.NET MVC的未来。

Finally, even when you are using Web Forms, you can always use .ashx files (basic IHttpHandler and it's asynchronous cousin, IHttpAsyncHandler) or web services with the ScriptService attribute. These options will also migrate fine should you decide to use ASP.NET MVC in the future.

这篇关于jQueryMobile在ASP.NET Web窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆