Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 30-Aug-11 9:27am
ekolis3.6K
Comments
SAKryukov at 31-Aug-11 0:14am
   
I would say, quite reasonable question, my 5.
--SA
supriya chaladi at 31-Aug-11 1:55am
   
No one could have thought in this way.
nice Question? makes us to think?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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. Smile | :)
  Permalink  
Comments
Uday P.Singh at 30-Aug-11 16:36pm
   
nice link my 5!
SAKryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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).
  Permalink  
Comments
Mas11 at 20-Sep-13 3:09am
   
Agree with you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
v2
Comments
Uday P.Singh at 1-Sep-11 3:55am
   
interesting my 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  
Comments
CHill60 at 6-Dec-13 11:28am
   
Reason for my downvote - essentially the same answer as solution 5 from 1 year ago
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

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";
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 405
1 Sergey Alexandrovich Kryukov 220
2 Maciej Los 195
3 Peter Leow 190
4 DamithSL 174


Advertise | Privacy | Mobile
Web02 | 2.8.140705.1 | Last Updated 6 Dec 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid