gpt4 book ai didi

asp.net - 为什么 ASP.NET Webforms 需要 Runat ="Server"属性?

转载 作者:行者123 更新时间:2023-12-03 04:10:18 24 4
gpt4 key购买 nike

为什么我必须在所有 ASP.NET 控件上指定 runat="server",因为它是强制属性,并且 server 是我的控件中唯一可用的选项。对 ASP.NET 的了解有限,不使用就会报错?

我确实了解我可以选择在 HTML 标记上使用它,并且我确实了解客户端/服务器范例及其实际指定的内容。

它是一个冗余标签,可能只是由该控件是 ASP.NET 控件所暗示,还是有根本原因?

最佳答案

我一直相信,您可以混合使用 ASP.NET 标记和 HTML 标记,并且 HTML 标记可以选择 runat="server" 。或不。保留该标记不会造成任何损害,但将其删除会导致编译器错误。你暗示的关于网络语言的东西越多,对于一个崭露头角的程序员来说,学习它就越不容易。这是对标签属性进行详细说明的一个很好的理由。

此对话是在 Mike Schinkel 的 Blog 上进行的他本人和微软国家服务部的塔尔博特·克罗威尔 (Talbot Crowell) 之间的对话。相关信息如下(由于来源中的语法错误,第一段被解释):

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

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.

继续:

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.

他继续说道:

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 - 为什么 ASP.NET Webforms 需要 Runat ="Server"属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/304290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com