Forum Moderators: open

Message Too Old, No Replies

What is the purpose of runat tag

         

andrewsmd

9:09 pm on Nov 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know you add it to everything but I guess my question is what is the purpose? Can you specify a different value than server. If so, what other values and why? Thanks,

Ocean10000

9:12 pm on Nov 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The runat tag is ment to tell the asp.net/asp processor that it should be processed on the Server. If it states anything other then "Server" it will be ignored and left to the client browser to process.

andrewsmd

11:00 pm on Nov 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I knew it did that, I guess I just didn't understand why you had to give it a value. Thanks,

mattglet

4:25 pm on Nov 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mostly because you can attach the runat attribute to regular HTML controls (<input>, <img>, <a>, etc.), not just server controls (<asp:Button>, <asp:Image>, <asp:Hyperlink>). Attaching the "runat" to an HTML control will allow you to access it server-side, as I'm sure you know.

As for having to give it a value, I'm not sure what the alternative is?

andrewsmd

4:56 pm on Nov 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the input. I guess I just didn't see why it has to equal something. Why can't it just be runat? I'm sure there is some grander scheme of things that I don't know about. I was just being curious.

mattglet

10:05 pm on Nov 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's primarily because of proper coding standards:

You shouldn't create an property (which is what the "runat" declaration is) without a value.