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.

About Jason

Jason est un entrepreneur expérimenté et développeur de logiciels qualifié dans le leadership, le développement mobile, la synchronisation des données et l’architecture SaaS. Il a obtenu son baccalauréat ès sciences (B.S.) en informatique de l’Université d’État de l’Arkansas.
View all posts by Jason →

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *