Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 12th, 2007, 03:13 PM
Authorized User
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Highlighting a textbox in a formview


I am trying to highlight an active textbox in a formview, but I am not having much success.

The attached code works fine when a textbox is in a form but not when it is in a formview. When the formview is first displayed (item mode), the items in the formview are represented as label controls. When the Insert button is selected, the trace output for the page indicates that textboxes are being rendered, but in the code the 'ctl' parameter is still a label. When the cancel button is then selected the trace output indicates that labels are being redisplayed in the formview, but the 'ctl' parameter is now a textbox. Bit late really, now that the attribute for onfocus and onblur are now being added and the control is not displayed.

The attributes are added on the Page_Load event, but I have tried later events with no success. Could someone explain to me why the formview behaves in this fashion, and how I can get its textboxes for insert and edit mode highlighted when they are active.

Thanks for any help

Andy M

Here's the code (I have got this of a ASP.NET site) :-

    Sub SetInputControlColors(ByVal ctl As WebControl, _
    ByVal backColor As Color, _
    ByVal foreColor As Color, _
    ByVal focusBackColor As Color, _
    ByVal focusForeColor As Color)

        Dim jsOnFocus As String = String.Format( _
        "this.style.backgroundColor = '{0}';" _
        & "this.style.color = '(1)';", _
        focusBackColor.Name, focusForeColor.Name)
        Dim jsOnBlur As String = String.Format( _
        "this.style.backgroundColor = '{0}';" _
        & "this.style.color = '(1)';", _
        backColor.Name, foreColor.Name)
        ctl.Attributes.Add("onfocus", jsOnFocus)
        ctl.Attributes.Add("onblur", jsOnBlur)
    End Sub

    Sub SetAllInputControlsColors(ByVal parent As _
        Control, ByVal backColor As Color, _
        ByVal foreColor As Color, _
        ByVal focusBackColor As Color, _
        ByVal focusForeColor As Color)
        For Each ctl As Control In parent.Controls
            If TypeOf ctl Is TextBox OrElse _
             TypeOf ctl Is ListBox OrElse _
             TypeOf ctl Is DropDownList Then
                SetInputControlColors(DirectCast( _
                ctl, WebControl), _
                backColor, foreColor, _
                focusBackColor, _
                SetAllInputControlsColors(ctl, _
                        backColor, foreColor, _
                        focusBackColor, _
            End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        SetAllInputControlsColors(Me, SystemColors.Window, SystemColors.WindowText, Color.Yellow, Color.Blue)

    End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference a textbox in a formview amatytfc ASP.NET 2.0 Basics 12 September 26th, 2007 11:36 AM
textbox initialization in Formview ekwong ASP.NET 2.0 Basics 2 November 17th, 2006 08:30 PM
Populate a Textbox in a Formview timeware ASP.NET 2.0 Basics 0 September 29th, 2006 10:08 AM
I have another highlighting problem. gilgalbiblewheel Classic ASP Databases 2 July 20th, 2005 02:02 PM
Highlighting in a datalist olambe Classic ASP Components 3 August 23rd, 2004 06:54 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.