Archive, ASP.NET
     

Runat Server

As an ASP.NET developer you have undoubtedly seen controls with their runat property set to the value server. Other than being a required property, what does that property really mean?

ASP.NET is what is referred to as a server-side technology. What that means is that portions of your ASP.NET application will be ran on a web server before even reaching your users web browser.

The way the web server knows which portions of your ASPX to execute and which portions to leave as-is is determined by the runat property. Any control with runat=”server” is preprocessed by the ASP.NET runtime, and any control lacking it is left alone. Worth pointing out is that any control, even regular HTML tags can be ran at the server.

	<div id="divExample" runat="server" />

With a normal div tag executed on the server, we can programmatically control that element from C# or VB.NET before its HTML is sent across the Internet. So, for example, you could make this particular div hidden by modifying its CSS styling on your Page_Load event.

	divExample.Style["display"] = "none";

This particular technique is useful for cleaning up the rendered HTML, and also allows for easy JavaScript manipulation of elements. In ASP.NET MVC this can also be an extremely powerful way to make up for lost functionality, as any control dependent upon ViewState is unavailable.

Never miss an article! Subscribe to my newsletter and I'll keep you updated with the latest content.

 

About Jason

Jason is an experienced entrepreneur & software developer skilled in leadership, mobile development, data synchronization, and SaaS architecture. He earned his Bachelor of Science (B.S.) in Computer Science from Arkansas State University.
View all posts by Jason →

Leave a Reply

Your email address will not be published. Required fields are marked *