Monday, March 12, 2012

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 JYou 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/d...ericcontrol.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/s...ns/ms03-026.asp

"Jerry J" <JanofskyJNoSpam@.NospamIntegrisolve.com> wrote in message
news:01be01c36426$4dc72ee0$a101280a@.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
Don't forget runat="server" in the body tag

"Ken Cox [Microsoft MVP]" <BANSPAMken_cox@.sympatico.ca> wrote in message
news:u$LHrFDZDHA.1620@.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/d...ericcontrol.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/s...ns/ms03-026.asp
>
> "Jerry J" <JanofskyJNoSpam@.NospamIntegrisolve.com> wrote in message
> news:01be01c36426$4dc72ee0$a101280a@.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
I think it is there.

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

"MS News (MS ILM)" <sql_agentman@.hotmail.com> wrote in message
news:%238IfrWDZDHA.1128@.tk2msftngp13.phx.gbl...
Don't forget runat="server" in the body tag

"Ken Cox [Microsoft MVP]" <BANSPAMken_cox@.sympatico.ca> wrote in message
news:u$LHrFDZDHA.1620@.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/d...ericcontrol.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/s...ns/ms03-026.asp
>
> "Jerry J" <JanofskyJNoSpam@.NospamIntegrisolve.com> wrote in message
> news:01be01c36426$4dc72ee0$a101280a@.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
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]" <BANSPAMken_cox@.sympatico.ca> wrote in message
news:eP6NWgDZDHA.2032@.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/s...ns/ms03-026.asp
>
> "MS News (MS ILM)" <sql_agentman@.hotmail.com> wrote in message
> news:%238IfrWDZDHA.1128@.tk2msftngp13.phx.gbl...
> Don't forget runat="server" in the body tag
>
> "Ken Cox [Microsoft MVP]" <BANSPAMken_cox@.sympatico.ca> wrote in message
> news:u$LHrFDZDHA.1620@.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/d...ericcontrol.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/s...ns/ms03-026.asp
> > "Jerry J" <JanofskyJNoSpam@.NospamIntegrisolve.com> wrote in message
> > news:01be01c36426$4dc72ee0$a101280a@.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
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/s...ns/ms03-026.asp

"MS News (MS ILM)" <sql_agentman@.hotmail.com> wrote in message
news:%23j8G2oDZDHA.1832@.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.
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 version
>of 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 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/s...bulletins/ms03-
026.asp
>
>"Jerry J" <JanofskyJNoSpam@.NospamIntegrisolve.com> wrote
in message
>news:01be01c36426$4dc72ee0$a101280a@.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
>
>.

0 comments:

Post a Comment