Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
4.23/5 (9 votes)
See more:
Why in the name of all that's holy does ASP.NET still require runat="server" all over the place? I understand that initially there were to be multiple options for the runat attribute, so you could have runat="client" or runat="myemergencybackupserverinshanghai" or whatnot, but since none of those were ever implemented, the runat="server" attribute serves only to crash sites that leave it out by mistake! So, anyone with more knowledge of ASP.NET than me, WHY is this godawful construct still there?
Posted
Comments
Sergey Alexandrovich Kryukov 31-Aug-11 0:14am    
I would say, quite reasonable question, my 5.
--SA
raj ch 31-Aug-11 1:55am    
No one could have thought in this way.
nice Question? makes us to think?

Here's [^] a discussion from a couple of years back on that subject. Not sure if it's helpful or not, but it was interesting. :)
 
Share this answer
 
Comments
Uday P.Singh 30-Aug-11 16:36pm    
nice link my 5!
Sergey Alexandrovich Kryukov 31-Aug-11 0:16am    
Yes, pretty interesting, even though it all is totally casuistic in essence, but it's hard to fight against such things... :-) My 5.
--SA
My 2 cents : how would it know if its a clientside control or server side. e.g. you can add this tag to HTML controls and use it in server code. I would agree to some extent that ASP.NET server controls can automate this process (i.e. not relying on user to add this tag).
 
Share this answer
 
Comments
Mas11 20-Sep-13 3:09am    
Agree with you.
First solution of pretty clear. Here is one interesting thread which you people may find useful. Very old thread, but having good discussion.
http://forums.asp.net/p/767126/767612.aspx[^]

Read this area.
Internet Explorer supports DHTML behaviors. 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
 
Share this answer
 
v2
Comments
Uday P.Singh 1-Sep-11 3:55am    
interesting my 5!
XML
Use the runat=server attribute when you're using ASP.NET controls, and/or you require programmatic access to those controls in your code-behind.

HTML controls don't require this attribute. It's useful if you have any HTML element like <span> <div>, or <table> when you want the ability to access them in code-behind.

<asp:Label runat="server" id="foo" />
<div runat="server" id="bar />
...
foo.Text = "Hello Label";
foo.Attributes["class"] = "baz";
 
Share this answer
 
If you don't use runat server attribute with your control, then u won't be able to access the control via code-behind. I hope it makes you clear.
 
Share this answer
 
Comments
CHill60 6-Dec-13 11:28am    
Reason for my downvote - essentially the same answer as solution 5 from 1 year ago

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900