Why do ASP.Net server control declarations require the runat="server" attribute?
Asked Answered
A

1

5

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?

Assignee answered 17/7, 2009 at 14:50 Comment(1)
G
8

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.

Gloriagloriana answered 17/7, 2009 at 14:54 Comment(1)
I would have closed my question as a duplicate (also see below) but it wont let me. Any ideas?Assignee

© 2022 - 2024 — McMap. All rights reserved.