This post originated from an RSS feed registered with .NET Buzz
by Doug Thews.
Original Post: Changing HTML Element Attributes in Codebehind
Feed Title: IlluminatiLand
Feed URL: http://apps5.oingo.com/apps/domainpark/domainpark.cgi?client=netw8744&s=JETBRAINS.COM
Feed Description: A technology blog for people enlightened enough to think for themselves
Sometimes, you'd like to manage the properties of plain HTML elements during the postback process. Well, you can by using the Attributes property of the HtmlGenericControl
For example, let's say you wanted to dynamically change the element's background color during postback. The first step would to be to manually define the BODY element in the codebehind (as we learned from a previous example, the VS.NET IDE does not do this for you). In your ASPX file, you would modify the element to look something like this:
Then, in your VB.NET codebehind file, you would add the reference:
Protected body As
System.Web.UI.HtmlControls.HtmlGenericControl
Now, to manipulate the background color attribute of this generic HTML control, just use the Attributes property:
body.Attributes("bgcolor") = ""
Use this to provide more spice to your ASP.NET web applications when you use plain HTML controls.