为什么ASP.Net服务器控件声明需要runat =“server”属性?

时间:2022-04-01 15:55:41

Surely the fact that they're declared beginning with "<asp:" is enough to infer they're server controls? Or is it just included for completeness (so they look similar to the server control declaration of <input runat="server" for example). Or is there some special reason?

当然,他们被宣布以“ ”开头的事实足以推断他们是服务器控件吗?或者只是为了完整而包含它(因此它们看起来类似于

It just always bugs me that the compiler tells me I've missed it off when I do so accidentally. Kind of like the thinking behind "var" - if the compiler knows what it is.. why bother expecting me to state it?

它总是让我感到困惑,编译器告诉我,当我不小心这样做时,我已经错过了它。有点像“var”背后的想法 - 如果编译器知道它是什么..为什么要求我说出来呢?

1 个解决方案

#1


Taken from this forum thread:

摘自此论坛帖子:

Internet Explorer supports DHTML behaviors.

Internet Explorer支持DHTML行为。

[The asp:control syntax] does not mean server control. You can create client DHTML component that has namespace and will run on the client machine. Also, namespaces are allowed in XHTML and techically you can use asp namespace for something else on a client, if you wish. Runat="server" prevents namespace *. If element has no runat="server" attribute, it will be sent to the client browser unchanged. Therefore, you can use HTML components (HTCs) in ASP.NET pages as well.

[asp:control语法]并不意味着服务器控制。您可以创建具有命名空间的客户端DHTML组件,并将在客户端计算机上运行。此外,在XHTML中允许使用名称空间,如果您愿意,可以在客户端上使用asp名称空间作为其他内容。 Runat =“server”可防止命名空间冲突。如果element没有runat =“server”属性,它将不加改变地发送到客户端浏览器。因此,您也可以在ASP.NET页面中使用HTML组件(HTC)。

Have a look here

看看这里

http://msdn.microsoft.com/workshop/author/behaviors/howto/creating.asp http://msdn.microsoft.com/workshop/author/behaviors/overview.asp

Mike Schinkel also has a blog post exploring why runat=server is necessary.

Mike Schinkel还有一篇博客文章,探讨为什么runat = server是必要的。

#1


Taken from this forum thread:

摘自此论坛帖子:

Internet Explorer supports DHTML behaviors.

Internet Explorer支持DHTML行为。

[The asp:control syntax] does not mean server control. You can create client DHTML component that has namespace and will run on the client machine. Also, namespaces are allowed in XHTML and techically you can use asp namespace for something else on a client, if you wish. Runat="server" prevents namespace *. If element has no runat="server" attribute, it will be sent to the client browser unchanged. Therefore, you can use HTML components (HTCs) in ASP.NET pages as well.

[asp:control语法]并不意味着服务器控制。您可以创建具有命名空间的客户端DHTML组件,并将在客户端计算机上运行。此外,在XHTML中允许使用名称空间,如果您愿意,可以在客户端上使用asp名称空间作为其他内容。 Runat =“server”可防止命名空间冲突。如果element没有runat =“server”属性,它将不加改变地发送到客户端浏览器。因此,您也可以在ASP.NET页面中使用HTML组件(HTC)。

Have a look here

看看这里

http://msdn.microsoft.com/workshop/author/behaviors/howto/creating.asp http://msdn.microsoft.com/workshop/author/behaviors/overview.asp

Mike Schinkel also has a blog post exploring why runat=server is necessary.

Mike Schinkel还有一篇博客文章,探讨为什么runat = server是必要的。