I've been asked by a few folks to provide a VB equivalent of the example C# web control I wrote about in this DotNetJunkies article. It's taken me a few weeks to get around to it, but here's a quick translation (note, the formatting in .Text made this messy -- but I'm not going to bother reformating the post. You can copy and paste and be in fine shape. Enjoy!
Imports System.ComponentModel
Imports System.Web.UI
imports System.Drawing
<assembly: TagPrefix( "ControlLib" , "lib") >
namespace ControlLib
Public Class PimpedOutTextbox :
Inherits System.Web.UI.WebControls.TextBox
Private _colOff As Color
Private _colOn as Color
<Category( "Appearance" ), Description( "The background color when the control loses focus" )> _
public Property BackColorOff as Color
get
return _colOff
end get
set( val as Color )
_colOff = val
end set
end property
<Category( "Appearance" ), Description( "The background color when the control has the focus" )> _
public Property BackColorOn as Color
get
return _colOn
end get
set( val as Color )
_colOn = val
end set
end property
protected overrides sub AddAttributesToRender( writer as HtmlTextWriter )
MyBase.AddAttributesToRender( writer )
'only add the client-side javascript for IE
if( System.Web.HttpContext.Current.Request.Browser.Type.IndexOf( "IE" ) > -1 ) then
writer.AddAttribute( "onFocus", "JavaScript:this.style.backgroundColor='" + ColorTranslator.ToHtml( _colOn ) + "';" )
if( _colOff.Equals( Color.Empty ) ) then
_colOff = Me.BackColor
end if
writer.AddAttribute( "onBlur", "JavaScript:this.style.backgroundColor='" + ColorTranslator.ToHtml( _colOff ) + "';" )
end if
End Sub
End Class
End NameSpace