Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 525
Ray Avatar asked Jul 17 '09 14:07

Ray


People also ask

Which attribute is mandatory for all ASP server control?

ASP.NET Web Server Controls Like HTML server controls, Web server controls are also created on the server and they require a runat="server" attribute to work.

What is the meaning of runat server property?

The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts. In the following example we declare an HtmlAnchor server control in an .aspx file.

What is script runat server?

The RUNAT=SERVER attribute tells the Web server to process the script on the server. If you do not set this attribute, the script is processed by the client browser.

What is runat server in C#?

Runat='Server ' Indicates the accessibility of the control at Serverside. Let Me make you more clear about it. If you puts runat="server" inside any of the control then you can use that control at the server side. e.g. XML.


1 Answers

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.

like image 164
Matthew Jones Avatar answered Dec 19 '22 09:12

Matthew Jones