Help: Changing background color dynamically

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

I am trying to change some webform's background color based on a value in my
web.config file.

This is how I am doing it:
' set background color based on web.config setting
Dim Body As New HtmlGenericControl
Body = CType(Page.Controls(1), HtmlGenericControl)
Body.Attributes("bgcolor") =
ConfigurationSettings.AppSettings("BackgroundColor")

For most pages in my web app it works FINE. But for some new pages it is not
working.
For the ones that work, page.Controls(1).tostring is equal to
"System.Web.UI.HtmlControls.HtmlGenericControl".
For the ones that don't work it's equal to
"System.Web.UI.HtmlControls.HtmlForm" and the CType fails.

Any ideas?
 
If I was you, I'd be using the "Style" to this sort of thing, heres an
example I did a while ago...
objCell.Style.Add("color","Red");
 
Any example online? I don't know what CSS classes are, but would like to
find out more.
 
It's a internet dev basic...

You have to create a style sheet
with
..withBorders {
BORDER: black thin solid
}

Link it to your page

in your html tag add class="classname"



like

<IMG SRC="blablabla" class="withBorders" />
 
not classes, CSS (Cascading Style Sheet).
Plenty of samples out there, do a MS search or google.
It's a function of html really.
 
The problem is not with trying to change the background color. You
are getting an error on this line...

Body = CType(Page.Controls(1), HtmlGenericControl)

As you said, the pages that have the problem are HTMLForm controls.
You are getting an error trying to Convert a HTMLForm to a
HTMLGenericControl. I would suggest casting to a "Control" type

Neil
 
Back
Top