469,609 Members | 1,666 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Web Form Background color


Is there a way to change the background color of a web
form on the server before it is posted? In the pageLoad
event I can do it to server controls by adding an
attribute, however, how do I do the same for the page's
background color?

Should be simple I think?

Jerry J
Nov 17 '05 #1
6 4645
You need to use the HtmlGenericControl. The code below is a code-behind version
of an example near the bottom of this page:

http://msdn.microsoft.com/library/de...riccontrol.asp

Does this help?

Ken
MVP [ASP.NET]

Public Class bdycolour
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents ColorSelect As System.Web.UI.HtmlControls.HtmlSelect
Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Public Sub SubmitBtn_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Submit1.ServerClick
Dim Body As New HtmlGenericControl
Body = Page.Controls(1)
Body.Attributes("bgcolor") = ColorSelect.Value
End Sub
End Class


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="bdycolour.aspx.vb"
Inherits="p733workev.bdycolour"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>bdycolour</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body id="Body" runat="server">
<h3>Updating Styles with the HtmlGenericControl</h3>
<form runat="server" id="Form1">
<p>
Select a background color for the page:
<p>
<select id="ColorSelect" runat="server" name="ColorSelect">
<option selected>White</option>
<option>Wheat</option>
<option>Gainsboro</option>
<option>LemonChiffon</option>
</select>
<input type="submit" runat="server" value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1"
name="Submit1">
</form>
</P>
</body>
</html>
--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp

"Jerry J" <Ja*************@NospamIntegrisolve.com> wrote in message
news:01****************************@phx.gbl...

Is there a way to change the background color of a web
form on the server before it is posted? In the pageLoad
event I can do it to server controls by adding an
attribute, however, how do I do the same for the page's
background color?

Should be simple I think?

Jerry J
Nov 17 '05 #2
Don't forget runat="server" in the body tag
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
You need to use the HtmlGenericControl. The code below is a code-behind version of an example near the bottom of this page:

http://msdn.microsoft.com/library/de...riccontrol.asp
Does this help?

Ken
MVP [ASP.NET]

Public Class bdycolour
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents ColorSelect As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Public Sub SubmitBtn_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Submit1.ServerClick
Dim Body As New HtmlGenericControl
Body = Page.Controls(1)
Body.Attributes("bgcolor") = ColorSelect.Value
End Sub
End Class


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="bdycolour.aspx.vb" Inherits="p733workev.bdycolour"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>bdycolour</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body id="Body" runat="server">
<h3>Updating Styles with the HtmlGenericControl</h3>
<form runat="server" id="Form1">
<p>
Select a background color for the page:
<p>
<select id="ColorSelect" runat="server" name="ColorSelect">
<option selected>White</option>
<option>Wheat</option>
<option>Gainsboro</option>
<option>LemonChiffon</option>
</select>
<input type="submit" runat="server" value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1"
name="Submit1">
</form>
</P>
</body>
</html>
--
Microsoft MVPs have a question for *you*: Are you patched against the Worm? http://www.microsoft.com/security/se...s/ms03-026.asp

"Jerry J" <Ja*************@NospamIntegrisolve.com> wrote in message
news:01****************************@phx.gbl...

Is there a way to change the background color of a web
form on the server before it is posted? In the pageLoad
event I can do it to server controls by adding an
attribute, however, how do I do the same for the page's
background color?

Should be simple I think?

Jerry J

Nov 17 '05 #3
I think it is there.

--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp

"MS News (MS ILM)" <sq**********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Don't forget runat="server" in the body tag
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
You need to use the HtmlGenericControl. The code below is a code-behind version of an example near the bottom of this page:

http://msdn.microsoft.com/library/de...riccontrol.asp
Does this help?

Ken
MVP [ASP.NET]

Public Class bdycolour
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents ColorSelect As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Public Sub SubmitBtn_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Submit1.ServerClick
Dim Body As New HtmlGenericControl
Body = Page.Controls(1)
Body.Attributes("bgcolor") = ColorSelect.Value
End Sub
End Class


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="bdycolour.aspx.vb" Inherits="p733workev.bdycolour"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>bdycolour</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body id="Body" runat="server">
<h3>Updating Styles with the HtmlGenericControl</h3>
<form runat="server" id="Form1">
<p>
Select a background color for the page:
<p>
<select id="ColorSelect" runat="server" name="ColorSelect">
<option selected>White</option>
<option>Wheat</option>
<option>Gainsboro</option>
<option>LemonChiffon</option>
</select>
<input type="submit" runat="server" value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1"
name="Submit1">
</form>
</P>
</body>
</html>
--
Microsoft MVPs have a question for *you*: Are you patched against the Worm? http://www.microsoft.com/security/se...s/ms03-026.asp

"Jerry J" <Ja*************@NospamIntegrisolve.com> wrote in message
news:01****************************@phx.gbl...

Is there a way to change the background color of a web
form on the server before it is posted? In the pageLoad
event I can do it to server controls by adding an
attribute, however, how do I do the same for the page's
background color?

Should be simple I think?

Jerry J


Nov 17 '05 #4
Yes it is, I did not copy your code and when I tried it I forgot the
runat="server" myself
so I am just trying to save someone some time in case if they don't copy
your code.

Thank you.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
I think it is there.

--
Microsoft MVPs have a question for *you*: Are you patched against the Worm? http://www.microsoft.com/security/se...s/ms03-026.asp

"MS News (MS ILM)" <sq**********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Don't forget runat="server" in the body tag
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
You need to use the HtmlGenericControl. The code below is a code-behind

version
of an example near the bottom of this page:

http://msdn.microsoft.com/library/de...riccontrol.asp

Does this help?

Ken
MVP [ASP.NET]

Public Class bdycolour
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents ColorSelect As

System.Web.UI.HtmlControls.HtmlSelect
Protected WithEvents Submit1 As

System.Web.UI.HtmlControls.HtmlInputButton

'NOTE: The following placeholder declaration is required by the Web

Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Public Sub SubmitBtn_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Submit1.ServerClick
Dim Body As New HtmlGenericControl
Body = Page.Controls(1)
Body.Attributes("bgcolor") = ColorSelect.Value
End Sub
End Class


<%@ Page Language="vb" AutoEventWireup="false"

Codebehind="bdycolour.aspx.vb"
Inherits="p733workev.bdycolour"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>bdycolour</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body id="Body" runat="server">
<h3>Updating Styles with the HtmlGenericControl</h3>
<form runat="server" id="Form1">
<p>
Select a background color for the page:
<p>
<select id="ColorSelect" runat="server" name="ColorSelect">
<option selected>White</option>
<option>Wheat</option>
<option>Gainsboro</option>
<option>LemonChiffon</option>
</select>
<input type="submit" runat="server" value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1"
name="Submit1">
</form>
</P>
</body>
</html>
--
Microsoft MVPs have a question for *you*: Are you patched against the

Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp

"Jerry J" <Ja*************@NospamIntegrisolve.com> wrote in message
news:01****************************@phx.gbl...

Is there a way to change the background color of a web
form on the server before it is posted? In the pageLoad
event I can do it to server controls by adding an
attribute, however, how do I do the same for the page's
background color?

Should be simple I think?

Jerry J


Nov 17 '05 #5
Okay. I understand now what you meant. Thanks.

--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp

"MS News (MS ILM)" <sq**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Yes it is, I did not copy your code and when I tried it I forgot the
runat="server" myself
so I am just trying to save someone some time in case if they don't copy
your code.

Thank you.

Nov 17 '05 #6

Ken,

Thanks for the information. I don't understand how it
works, but I am going to give it a try.

Thanks

Jerry J

-----Original Message-----
You need to use the HtmlGenericControl. The code below is a code-behind versionof an example near the bottom of this page:

http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/cpgenref/html/cpconhtmlgenericcontrol.asp
Does this help?

Ken
MVP [ASP.NET]

Public Class bdycolour
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents ColorSelect As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton
'NOTE: The following placeholder declaration is required by the Web FormDesigner.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Public Sub SubmitBtn_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Submit1.ServerClick
Dim Body As New HtmlGenericControl
Body = Page.Controls(1)
Body.Attributes("bgcolor") = ColorSelect.Value
End Sub
End Class


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="bdycolour.aspx.vb"Inherits="p733workev.bdycolour"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
<head>
<title>bdycolour</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body id="Body" runat="server">
<h3>Updating Styles with the HtmlGenericControl</h3>
<form runat="server" id="Form1">
<p>
Select a background color for the page:
<p>
<select id="ColorSelect" runat="server" name="ColorSelect"> <option selected>White</option>
<option>Wheat</option>
<option>Gainsboro</option>
<option>LemonChiffon</option>
</select>
<input type="submit" runat="server" value="Apply"
onserverclick="SubmitBtn_Click" id="Submit1"
name="Submit1">
</form>
</P>
</body>
</html>
--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?http://www.microsoft.com/security/se...ulletins/ms03- 026.asp
"Jerry J" <Ja*************@NospamIntegrisolve.com> wrote in messagenews:01****************************@phx.gbl...

Is there a way to change the background color of a web
form on the server before it is posted? In the pageLoad
event I can do it to server controls by adding an
attribute, however, how do I do the same for the page's
background color?

Should be simple I think?

Jerry J
.

Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by mattaku | last post: by
1 post views Thread by news.wanadoo.nl | last post: by
2 posts views Thread by alwaysintune | last post: by
6 posts views Thread by shapper | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.