简体   繁体   English

是否在浏览器中启用JavaScript以获得有效的ASP.NET页面?

[英]Is enabling JavaScript in browser a MUST to get working ASP.NET pages?

This is a newbie question (I'm sure it is). 这是一个新手问题(我确定是这样)。 I have tried for the first time in a little ASP.NET web application I am working on what happens if I disable Javascript in a browser (I'm testing mainly with Firefox). 我第一次尝试在一个小的ASP.NET Web应用程序中,我正在研究如果我在浏览器中禁用Javascript会发生什么(我主要使用Firefox测试)。

Result: My application is completely broken, although I didn't ever write any single line of Javascript. 结果:我的应用程序完全坏了,虽然我没有编写任何单行的Javascript。

For instance: I have a link button on a page from a LoginStatus control. 例如:我在LoginStatus控件的页面上有一个链接按钮。 Looking at the generated HTML code in my browser I see this: 在我的浏览器中查看生成的HTML代码,我看到:

<a id="ctl00_ctl00_LoginStatus" href="javascript:__doPostBack('ctl00$ctl00$LoginStatus$ctl02','')">Login</a>

Similar with some link buttons in a ListView control which allow to sort the list by certain data fields: The href of the generated anchor tag contains this: javascript:WebForm_DoPostBackWithOptions(...) . 与ListView控件中的某些链接按钮类似,允许按特定数据字段对列表进行排序:生成的锚标记的href包含: javascript:WebForm_DoPostBackWithOptions(...)

So clicking on "Login" or trying to sort does not work without having Javascript enabled. 因此,如果没有启用Javascript,单击“登录”或尝试排序将无法正常工作。

Does this mean: With disabled Javascript in the browser ASP.NET applications won't work properly? 这是否意味着:在浏览器中禁用Javascript ASP.NET应用程序将无法正常工作? Or what do I have to do to get the application working with disabled Javascript? 或者我需要做些什么来使应用程序使用禁用的Javascript?

Thanks for your feedback! 感谢您的反馈意见!

Some stuff will work, some won't (see here ). 有些东西会起作用,有些则不会(见这里 )。 This is not to say you can't use ASP.NET without Javascript, you'll just have to avoid the below mentioned controls (and I'm sure a plethora of 3rd party controls as well). 这并不是说你不能在没有Javascript的情况下使用ASP.NET,你只需要避免使用下面提到的控件(我确信还有很多第三方控件)。

The ASP.NET server controls that depend on being able to run client script include: 依赖于能够运行客户端脚本的ASP.NET服务器控件包括:

  • The LinkButton and HtmlButton server controls require script. LinkBut​​ton和HtmlButton服务器控件需要脚本。 (This is not true for the Button Web server control or the HtmlInputButton or HtmlInputImage controls.) (对于Button Web服务器控件或HtmlInputButton或HtmlInputImage控件,情况并非如此。)
  • By default, the Calendar control implements month navigation and day selection using LinkButton controls. 默认情况下,Calendar控件使用LinkBut​​ton控件实现月份导航和日期选择。 If you set control properties to allow users to select a day, week, or month, or if you allow users to navigate to other months, then the Calendar control will generate client script. 如果将控件属性设置为允许用户选择日,周或月,或者如果允许用户导航到其他月份,则Calendar控件将生成客户端脚本。 If you use the Calendar control simply to display a single month with no selection or navigation, the control does not require client script. 如果您使用Calendar控件只显示没有选择或导航的单个月,则控件不需要客户端脚本。
  • Any Web server control whose AutoPostBack property is set to true; AutoPostBack属性设置为true的任何Web服务器控件; the client script is required so that the control will post the page. 客户端脚本是必需的,以便控件将发布页面。
  • The Web validation controls, which require client script to support client-side validation. Web验证控件,需要客户端脚本支持客户端验证。 If the client does not support script, validation will run on the server only. 如果客户端不支持脚本,则验证仅在服务器上运行。

Unless you switch over to the ASP.NET MVC framework, yes, ASP.NET sites built with the web forms model requires JavaScript. 除非您切换到ASP.NET MVC框架,否则,使用Web表单模型构建的ASP.NET站点需要JavaScript。

Elements that have autopostback turned on, any linkbutton controls or button controls, and any client-side validation will cease to function, as you've discovered. 正如您所发现的那样,启用了autopostback元素,任何linkbutton控件或button控件,以及任何客户端验证都将停止运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM