change the value of a custom attribute on a <BODY> tag

C

Chris Millar

wondered if anyone could help me - i'm trying to control the value of an
attribute of the BODY tag on a page. So i've got:

<html>
<body test="colin">
<form ......
** content **
</form>
</body>
</html>

I want to affect the value of the 'test' attribute from the code-behind
file.

I've tried setting up the body tag as a server control (e.g. <body id="fred"
runat="server" test="colin">) and adding in a protected var in the
codebehind like this:
protected System.Web.UI.HtmlControls.HtmlGenericControl mainbody;

... but it throws an exception somewhere deep down in the .net libraries
before it runs any of my code. Anyone got any ideas about how I could do
this?
 
H

Hugo Wetterberg

The name of the HtmlGenericControl must be the same as the id in the
asp-page.

<body id="fred" runat="server" test="groovy"/>
protected System.Web.UI.HtmlControls.HtmlGenericControl fred;

Then you can manipulate and read the attributes serverside:
fred.Attributes["test"]=string.Format("{0} code",fred.Attributes["test"]);

/Hugo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top