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
|