Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 12th, 2007, 03:13 PM
Authorized User
 
Join Date: Nov 2006
Location: Bracknell, Berks, United Kingdom.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Highlighting a textbox in a formview

Hello

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, _
                focusForeColor)
            Else
                SetAllInputControlsColors(ctl, _
                        backColor, foreColor, _
                        focusBackColor, _
                        focusForeColor)
            End If
        Next
    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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:51 PM.


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