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

发布于 2024-07-27 17:56:42 字数 105 浏览 11 评论 0 原文

当然,它们以“

当我不小心这样做时,编译器告诉我我错过了它,这总是让我烦恼。 有点像“var”背后的想法 - 如果编译器知道它是什么......为什么还要期待我来陈述它呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稍尽春風 2024-08-03 17:56:42

摘自此论坛帖子

Internet Explorer 支持 DHTML
行为。

[asp:control语法]并不意味着服务器
控制。 您可以创建客户端 DHTML
具有命名空间并且将
在客户端机器上运行。 还,
XHTML 中允许命名空间,并且
从技术上讲,您可以使用 asp 命名空间
对于客户的其他事情,如果您
希望。 Runat="server" 阻止
命名空间冲突。 如果元素没有
runat="server" 属性,它将是
发送到客户端浏览器不变。
因此,您可以使用 HTML 组件
(HTC) 也在 ASP.NET 页面中。

看这里

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

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

Taken from this forum thread:

Internet Explorer supports DHTML
behaviors.

[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 clash. 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文