I learn something new today (I’m sure most of you already know, but I just found out). I didn’t know we can use html tags such as div, span etc as html server controls. I do know if you want to convert html controls into server control, you just have to add runat=”server” element but using div container as server control is a different story.

I normally use literal or panel server controls to show or hide the confirmation messages. But in this code, the div tag can act as a panel control by declaring it as HtmlGenericControl.

In the front-end you add id and runat=”server” elements to the div tag.

<fieldset>
	<h3>Registration Validation</h3>
	<div id="divValidated" runat="server">
		Your account has been validated. You may now log in.
	</div>
	<div id="divNoAccount" runat="server">
		No matching account. If it has been over 30 days since you registered your
		account will have been deleted. Please sign up again.
	</div>
	<div id="divNoNeed" runat="server">
		Your account has already been validated.
	</div>
</fieldset>

In the back-end you declare it as HtmlGenericControl.

protected System.Web.UI.HtmlControls.HtmlGenericControl divValidated;
protected System.Web.UI.HtmlControls.HtmlGenericControl divNoAccount;
protected System.Web.UI.HtmlControls.HtmlGenericControl divNoNeed;

Voila, you got your div panel with all those member variables you can make use of. So here is a little info on HtmlGenericControl.

Use this class to represent an HTML server control element not directly represented by a .NET Framework class, such as <span>, <div>, <body>, or <font>.
Caution
This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input.
HtmlGenericControl Class
HtmlGenericControl Members

Pretty cool isn’t it? Well, I didn’t know that and now I know. :D