runat=server
-
I am starting to make my first steps in the asp.net world. I run into something that wasn' t new to me, though its use in asp.net is something that to me seems totally different from what i knew before. I'm talking about the "runat=server" clause. Remembering classic asp, vbscript, I learned that "runat=server" was used to instruct the web server to elaborate the vbscript code subject to the clause itself, rather than send it to the client. In asp.net, it seems to be different. I read that it's used for "server side control" , that is, controls which are "run" on the server side. This is nonsense to me . How can a control be run on the server side, given that the server side obviously doesn't have a Gui (and if it has, probably it has nothing to do with the user session) ....? my suspicion is that a "server side" control, means a control which can be dealt with by a server side script or code behind snippet. But ... is this the right idea ? I read tons of documentation and articles but it seems none of them wants to be clear about this subject. I wonder how the documentation can be so fuzzy ... don't these guys ever ask themselves such simple questions ? Do they always take things for granted ?
-
I am starting to make my first steps in the asp.net world. I run into something that wasn' t new to me, though its use in asp.net is something that to me seems totally different from what i knew before. I'm talking about the "runat=server" clause. Remembering classic asp, vbscript, I learned that "runat=server" was used to instruct the web server to elaborate the vbscript code subject to the clause itself, rather than send it to the client. In asp.net, it seems to be different. I read that it's used for "server side control" , that is, controls which are "run" on the server side. This is nonsense to me . How can a control be run on the server side, given that the server side obviously doesn't have a Gui (and if it has, probably it has nothing to do with the user session) ....? my suspicion is that a "server side" control, means a control which can be dealt with by a server side script or code behind snippet. But ... is this the right idea ? I read tons of documentation and articles but it seems none of them wants to be clear about this subject. I wonder how the documentation can be so fuzzy ... don't these guys ever ask themselves such simple questions ? Do they always take things for granted ?
You are right, runat=server means the control is executed on server. Each control with such attribute is processed before page is ready to send to user and as a result only output html is visible for user, not the source code. To be honest, I never thought about it in your way. It was always like that - if you want your code executed use runat=server. So it may be the reason why it isn't explained much.
-- "My software never has bugs. It just develops random features."
-
I am starting to make my first steps in the asp.net world. I run into something that wasn' t new to me, though its use in asp.net is something that to me seems totally different from what i knew before. I'm talking about the "runat=server" clause. Remembering classic asp, vbscript, I learned that "runat=server" was used to instruct the web server to elaborate the vbscript code subject to the clause itself, rather than send it to the client. In asp.net, it seems to be different. I read that it's used for "server side control" , that is, controls which are "run" on the server side. This is nonsense to me . How can a control be run on the server side, given that the server side obviously doesn't have a Gui (and if it has, probably it has nothing to do with the user session) ....? my suspicion is that a "server side" control, means a control which can be dealt with by a server side script or code behind snippet. But ... is this the right idea ? I read tons of documentation and articles but it seems none of them wants to be clear about this subject. I wonder how the documentation can be so fuzzy ... don't these guys ever ask themselves such simple questions ? Do they always take things for granted ?
By using runat="server", controls are enhanced to enable server side processing. It means, you will be able to access the control and its properties on server side too. Without runat="server", you won't be able to access the control on server side (code behind file). It's not about GUI. It's about accessibility to the object and it's properties.
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog]: Sandeep Mewara's Tech Journal! [My Latest Article]: HTML5 Quick Start Web Application
-
I am starting to make my first steps in the asp.net world. I run into something that wasn' t new to me, though its use in asp.net is something that to me seems totally different from what i knew before. I'm talking about the "runat=server" clause. Remembering classic asp, vbscript, I learned that "runat=server" was used to instruct the web server to elaborate the vbscript code subject to the clause itself, rather than send it to the client. In asp.net, it seems to be different. I read that it's used for "server side control" , that is, controls which are "run" on the server side. This is nonsense to me . How can a control be run on the server side, given that the server side obviously doesn't have a Gui (and if it has, probably it has nothing to do with the user session) ....? my suspicion is that a "server side" control, means a control which can be dealt with by a server side script or code behind snippet. But ... is this the right idea ? I read tons of documentation and articles but it seems none of them wants to be clear about this subject. I wonder how the documentation can be so fuzzy ... don't these guys ever ask themselves such simple questions ? Do they always take things for granted ?
To elaborate on Sandeeps explanation a little more, ASP.Net objects can be used on a web form, that uses combinations of just plain old HTML and ASP.Net Objects such as the panel control. So you can do it 2 ways, 1 in straight HTML or 1 as an asp.net object
or
Now you can also create that object in code behind, or pure code
Dim panel_Container as Panel = new panel
with panel_container
.style.add(HtmlTextWriterStyle.float, "left")
end with
controls.add(panel_container)I don't know what the exact description is of using runat="Server" is, but I know you need it when using system.web objects on the web form, which is a .aspx page. The server will convert that object to HTML, and send the HTML back to the browser. So a Panel object is a set of div tags, a label is a span tag. I came from vb and asp classic and went to asp.net, and thought that all the elements on a webform has to be a asp.net object, but over the years, I learned how to better manage my time and produce consistent looking products by keeping asp.net objects to a minimum now. I just use straight HTML now, and only use asp.net object for things like master pages, or anything I need to interact with in code behind on the server side. I never us the object font attributes or colors anymore, and use CSS for that. In my opinion, don't get too crazy using the asp.net objects in the beginning, and just use html and CSS. As you start writing more code, then you can go back and convert some HTML to objects when needed.