ControlExtensions Module
Life With Nate
Nate's Poetry Page
Resume (PDF)
Nate's Code
ASP.NET 2.0/3.5
ButtonExtensions
CheckBoxValidator
ConditionalRequiredTextValidator
CSSImageMap
CustomStyle
DateTimePicker
DateTimePickerTemplated
LengthValidator
RestrictInputTextBox
RestrictInputValidator
Rollovers
ControlExtensions
ImageExtensions
RotatedTextHandler
RotatedTextImage
Rotators
SelectedCountValidator
SlideIntoView
StatesDropDownList
UniqueValueValidatorBase
VB.NET 2.0/3.5
Just For Fun
Windows Phone 7
Description
The ControlExtensions Module contains several Extension Methods that can be used with all WebControls and/or HtmlControls to simplify several common tasks.
Example
WebControl
Me.pnlWebControl1.AddRolloverBackgroundColor(Drawing.Color.Blue)
Me.imgWebControl1.AddRolloverBackgroundColor(Drawing.Color.Orange)
Me.pnlWebControl2.AddRolloverBackgroundColor(Drawing.Color.Blue, Drawing.Color.Red)
Me.imgWebControl2.AddRolloverBackgroundColor(Drawing.Color.Orange, Drawing.Color.Magenta)
HtmlControl
Me.divHtmlControl1.AddRolloverBackgroundColor(Drawing.Color.Blue)
Me.imgHtmlControl1.AddRolloverBackgroundColor(Drawing.Color.Orange)
Me.divHtmlControl2.AddRolloverBackgroundColor(Drawing.Color.Blue, Drawing.Color.Red)
Me.imgHtmlControl2.AddRolloverBackgroundColor(Drawing.Color.Orange, Drawing.Color.Magenta)
Properties & Methods
AddRolloverBackgroundColor(ByVal rollover As System.Drawing.Color)
This Extension Method can be used with all WebControls and HtmlControls to add a rollover which changes the background color. The rollover color will be the color specified, and the rollout color will be the CSS value 'transparent'.
rollover
- The background color used when the user rolls over the WebControl or HtmlControl
AddRolloverBackgroundColor(ByVal rollover As System.Drawing.Color, ByVal initial As System.Drawing.Color)
This Extension Method can be used with all WebControls and HtmlControls to add a rollover which changes the background color. The rollover and rollout colors will be the colors specified in the rollover and initial parameters.
rollover
- The background color used when the user rolls over the WebControl or HtmlControl
initial
- The color used as the initial background color and the background color when the user rolls out of the WebControl or HtmlControl
Source Code
ControlExtensions.vb:
Imports System.Runtime.CompilerServices Namespace NathanSokalski Public Module ControlExtensions <Extension()> Public Sub AddRolloverBackgroundColor(ByVal ctrl As WebControl, ByVal rollover As System.Drawing.Color) ctrl.Style.Add(System.Web.UI.HtmlTextWriterStyle.BackgroundColor, "transparent") ctrl.Attributes.Add("onmouseover", String.Format("this.style.backgroundColor='{0}';", System.Drawing.ColorTranslator.ToHtml(rollover))) ctrl.Attributes.Add("onmouseout", "this.style.backgroundColor='transparent';") End Sub <Extension()> Public Sub AddRolloverBackgroundColor(ByVal ctrl As WebControl, ByVal rollover As System.Drawing.Color, ByVal initial As System.Drawing.Color) ctrl.BackColor = initial ctrl.Attributes.Add("onmouseover", String.Format("this.style.backgroundColor='{0}';", System.Drawing.ColorTranslator.ToHtml(rollover))) ctrl.Attributes.Add("onmouseout", String.Format("this.style.backgroundColor='{0}';", System.Drawing.ColorTranslator.ToHtml(initial))) End Sub <Extension()> Public Sub AddRolloverBackgroundColor(ByVal ctrl As HtmlControl, ByVal rollover As System.Drawing.Color) ctrl.Style.Add(System.Web.UI.HtmlTextWriterStyle.BackgroundColor, "transparent") ctrl.Attributes.Add("onmouseover", String.Format("this.style.backgroundColor='{0}';", System.Drawing.ColorTranslator.ToHtml(rollover))) ctrl.Attributes.Add("onmouseout", "this.style.backgroundColor='transparent';") End Sub <Extension()> Public Sub AddRolloverBackgroundColor(ByVal ctrl As HtmlControl, ByVal rollover As System.Drawing.Color, ByVal initial As System.Drawing.Color) ctrl.Style.Add(System.Web.UI.HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(initial)) ctrl.Attributes.Add("onmouseover", String.Format("this.style.backgroundColor='{0}';", System.Drawing.ColorTranslator.ToHtml(rollover))) ctrl.Attributes.Add("onmouseout", String.Format("this.style.backgroundColor='{0}';", System.Drawing.ColorTranslator.ToHtml(initial))) End Sub End Module End Namespace
Remarks
When using the AddRolloverBackgroundColor Extension Methods with an ImageButton, be sure to keep in mind that the rollover will not work when Enabled="False".