473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

In the code behind: how to add a background attribute to the body tag.

In the .master file I have:
<body runat="server" id="MainBody">

I need to add a background attribute to MainBody in the .master.vb file.

But there it tells me that MainBody is not declared.

Now I'll try anything to see if I can get a hint of how to proceed. So I
try:

Dim zz As Control = Master.FindControl("MainBody")

But Master's value is nothing

I try

Dim zz As Control = FindControl("MainBody")

Seems to find it but Control does not have a background attribute to set.

So now I'm trying this NG.

Any suggestions as to how I can add that attribute???

Thanks

ps I know background is deprecated
Sep 23 '08 #1
4 2256
Assuming that "MainBody" is the ID of a ContentPlaceHolder on your masterpage

ContentPlaceHolders do not have any backround attribute. You should nest it
inside a DIV or so and alter that attribute instead.
"_Who" wrote:
In the .master file I have:
<body runat="server" id="MainBody">

I need to add a background attribute to MainBody in the .master.vb file.

But there it tells me that MainBody is not declared.

Now I'll try anything to see if I can get a hint of how to proceed. So I
try:

Dim zz As Control = Master.FindControl("MainBody")

But Master's value is nothing

I try

Dim zz As Control = FindControl("MainBody")

Seems to find it but Control does not have a background attribute to set.

So now I'm trying this NG.

Any suggestions as to how I can add that attribute???

Thanks

ps I know background is deprecated
Sep 23 '08 #2
Not on a ContentPlaceHolders.
It's on the <bodytag
thanks

"Louis Somers" <Lo*********@discussions.microsoft.comwrote in message
news:C7**********************************@microsof t.com...
Assuming that "MainBody" is the ID of a ContentPlaceHolder on your
masterpage

ContentPlaceHolders do not have any backround attribute. You should nest
it
inside a DIV or so and alter that attribute instead.
"_Who" wrote:
>In the .master file I have:

><body runat="server" id="MainBody">

>>
I need to add a background attribute to MainBody in the .master.vb file.

But there it tells me that MainBody is not declared.

Now I'll try anything to see if I can get a hint of how to proceed. So I
try:

Dim zz As Control = Master.FindControl("MainBody")

But Master's value is nothing

I try

Dim zz As Control = FindControl("MainBody")

Seems to find it but Control does not have a background attribute to set.

So now I'm trying this NG.

Any suggestions as to how I can add that attribute???

Thanks

ps I know background is deprecated

Sep 23 '08 #3
On Tue, 23 Sep 2008 10:13:56 -0400, "_Who"
<Ca**********@roadrunner.comwrote:
>In the .master file I have:
<body runat="server" id="MainBody">

I need to add a background attribute to MainBody in the .master.vb file.

But there it tells me that MainBody is not declared.

Now I'll try anything to see if I can get a hint of how to proceed. So I
try:

Dim zz As Control = Master.FindControl("MainBody")

But Master's value is nothing

I try

Dim zz As Control = FindControl("MainBody")

Seems to find it but Control does not have a background attribute to set.

So now I'm trying this NG.

Any suggestions as to how I can add that attribute???

Thanks

ps I know background is deprecated
Here are some solutions (sorry, I am using C#, not VB.NET):

1) Put the following into your Page_Load or Page_PreRender
(preferably) event handler method:

HtmlGenericControl body = Me.Page.FindControl( "MainBody" ) as
HtmlGenericControl;
body.Attributes["bgcolor"] = "#ffffcc";

2) To avoid looking up control by its name, declare it is explicitly
on your code-behind file by adding a protected page member variable
that has the same ID and correct object type:

protected HtmlGenericControl MainBody;

.....
and then in your event handler:

this.MainBody.Attributes["bgcolor"] = "#ccffff";
Keep in mind that you can add any custom attribute to any HTML control
this way. Also, the safer method maybe like follows, although I am not
sure why the above works as well:

this.MainBody.Attributes.Add( "myAttrib", "myValue" );

rather than

this.MainBody.Attributes["myAttrib"] = "myValue";

N-joy!
Sep 23 '08 #4
Thanks that fixed it
"Usenet User" <no*****@no.waywrote in message
news:eu********************************@4ax.com...
On Tue, 23 Sep 2008 10:13:56 -0400, "_Who"
<Ca**********@roadrunner.comwrote:
>>In the .master file I have:
<body runat="server" id="MainBody">

I need to add a background attribute to MainBody in the .master.vb file.

But there it tells me that MainBody is not declared.

Now I'll try anything to see if I can get a hint of how to proceed. So I
try:

Dim zz As Control = Master.FindControl("MainBody")

But Master's value is nothing

I try

Dim zz As Control = FindControl("MainBody")

Seems to find it but Control does not have a background attribute to set.

So now I'm trying this NG.

Any suggestions as to how I can add that attribute???

Thanks

ps I know background is deprecated

Here are some solutions (sorry, I am using C#, not VB.NET):

1) Put the following into your Page_Load or Page_PreRender
(preferably) event handler method:

HtmlGenericControl body = Me.Page.FindControl( "MainBody" ) as
HtmlGenericControl;
body.Attributes["bgcolor"] = "#ffffcc";

2) To avoid looking up control by its name, declare it is explicitly
on your code-behind file by adding a protected page member variable
that has the same ID and correct object type:

protected HtmlGenericControl MainBody;

....
and then in your event handler:

this.MainBody.Attributes["bgcolor"] = "#ccffff";
Keep in mind that you can add any custom attribute to any HTML control
this way. Also, the safer method maybe like follows, although I am not
sure why the above works as well:

this.MainBody.Attributes.Add( "myAttrib", "myValue" );

rather than

this.MainBody.Attributes["myAttrib"] = "myValue";

N-joy!

Sep 23 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: erik | last post by:
Is it posssible to inherit the previous pages (parent pages) background image? Is there a script out there I could look at? Thanks
4
by: Keon | last post by:
Hoi Do someone know how i can make the background of a iframe transparancy? I already tried it with filter: Alpha(Opacity=50,); but it also make the text transperancy. do someone know how to...
5
by: Derek Fountain | last post by:
I have a horizontal navigation bar, which is a single row table containing the right images. It "stretches" itself across the screen using a penultimate td like this: <td width="100%"...
7
by: Cliff Cavin | last post by:
How do I programatically change the background color of an aspx page in code? Is there something like Page.BgColor = "#FFFFFF" ? For that matter, how do I access any of the DOCUMENT...
1
by: Mike | last post by:
I want to change the background image of the html page within code based on the users selection. I'm trying to use this in the page onload even response.write("<body background=' & dataitem>") ...
12
by: GaryDean | last post by:
In the original post I failed so indicate that I am using framework 1.1....... I need to be able to change the background color of a page from code. I found an answer to this question in...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
6
by: Rob | last post by:
Hello, I'm sure this has come up before. I have need for a collection of all elements/objects in an HTML document that have any kind of an attribute (HTML or CSS) that is making use of a URL to...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.