CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Grant Killian's Blog

No, this has nothing to do with beer -- but maybe it should?

PimpedOutTextbox VB Style

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

 



Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!