为什么ASP.NET web表单需要的Runat ="服务器"属性? [英] Why does ASP.NET webforms need the Runat="Server" attribute?

查看:118
本文介绍了为什么ASP.NET web表单需要的Runat ="服务器"属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要指定 =服务器我所有的ASP.NET控件时,它是一个必需的属性和服务器在我有限的ASP.NET知识唯一的选择,如果我不使用它,我得到一个错误?

Why do I have to specify runat="server" on all my ASP.NET controls when it is a mandatory attribute and server is the only option available in my limited knowledge of ASP.NET, and I get an error if I don't use it?

我不明白,我可以选择使用它在我的HTML标记,我明白了客户机/服务器模式以及它实际上是指定。

I do understand that I can optionally use it on my HTML tags, and I do understand the client/server paradigm and what it is actually specifying.

难道可以只通过控制作为一个ASP.NET控件中隐含了多余的标签,或者是有一个潜在的原因是什么?

Is it a redundant tag that could just be implied by the control being an ASP.NET control, or is there an underlying reason?

推荐答案

我一直相信它的存在更多的为你可以混合ASP.NET标记和HTML标记和HTML标签的理解要么是的选项 =服务器与否。它没有伤害任何留在标签,它会导致一个编译器错误把它拿出来。在你暗示有关Web语言的更多的东西,不容易它是一个初露头角的程序员进来,学习它。这是因为任何要详细了解标签属性的好理由。

I've always believed it was there more for the understanding that you can mix ASP.NET tags and HTML Tags, and HTML Tags have the option of either being runat="server" or not. It doesn't hurt anything to leave the tag in, and it causes a compiler error to take it out. The more things you imply about web language, the less easy it is for a budding programmer to come in and learn it. That's as good a reason as any to be verbose about tag attributes.

这谈话对他和微软全国服务塔尔博特克罗韦尔之间迈克·辛克尔的博客。相关信息如下(第一段意译由于源语法错误):

This conversation was had on Mike Schinkel's Blog between himself and Talbot Crowell of Microsoft National Services. The relevant information is below (first paragraph paraphrased due to grammatical errors in source):

[...] 的,但&LT的重要性; =服务器> 更多的一致性和可扩展性。

[...] but the importance of <runat="server"> is more for consistency and extensibility.

如果开发商有标记一些标签(即&LT; ASP:/&GT; )的ASP.NET引擎忽略,那么就还有潜在的问题标签和未来的改进中命名空间冲突。通过要求&LT; =服务器方式&gt; 属性,这是否定

If the developer has to mark some tags (viz. <asp: />) for the ASP.NET Engine to ignore, then there's also the potential issue of namespace collisions among tags and future enhancements. By requiring the <runat="server"> attribute, this is negated.

它继续:

如果&LT; RUNAT =客户&GT; 中所需的所有客户端的标签,解析器需要分析所有的标签和剥离出 &LT; RUNAT =客户端方式&gt; 部分

If <runat=client> was required for all client-side tags, the parser would need to parse all tags and strip out the <runat=client> part.

他继续说道:

目前,
  如果我的猜测是正确的,解析器
  简单地忽略所有文本(标记或无
  标签),除非它与标签
   RUNAT =服务器属性或&LT;%
  preFIX或SSI&LT;! - #包括 ... (...)
  另外,由于ASP.NET被设计为
  让网页设计师分离
  从Web开发人员(foo.aspx)
  (foo.aspx.vb),网页设计师可以
  用他们自己的网页设计师工具
  地方HTML和客户端JavaScript
  而无需知道有关ASP.NET
  特定的标记或属性。

Currently, If my guess is correct, the parser simply ignores all text (tags or no tags) unless it is a tag with the runat=server attribute or a "<%" prefix or ssi "<!– #include(...) Also, since ASP.NET is designed to allow separation of the web designers (foo.aspx) from the web developers (foo.aspx.vb), the web designers can use their own web designer tools to place HTML and client-side JavaScript without having to know about ASP.NET specific tags or attributes.

这篇关于为什么ASP.NET web表单需要的Runat =&QUOT;服务器&QUOT;属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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