C
crjunk
Hi Everyone,
I have a web form that I would like to enhance. What I'd like to do
is this:
A user adds/edits the text in a textbox. I want the adjoining label to
change color.
Example:
User edits text in txtCaseNumber. The cursor leaves txtCaseNumber.
Code executes and turns lblCaseNumber text from black to red.
Here is what I've come up with so far:
Protected Sub txtCaseNumber_TextChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles txtCaseNumber.TextChanged
ChangeLabelColor(sender)
End Sub
Private Sub ChangeLabelColor(ByVal TextBox)
Dim labelID As String = TextBox.ID.replace("txt", "lbl")
Dim ctrl As New Control
Dim ctrlNameText As Label
For Each ctrl In Page.FindControl("aspnetForm").Controls
If TypeOf (ctrl) Is Label And (ctrl.ID.ToString.Trim =
labelID.Trim) Then
ctrlNameText = ctrl
ctrlNameText.ForeColor = Drawing.Color.Red
End If
Next
End Sub
The code bombs out on the For Each ctrl statement.
In debug mode, I'm receiving the following messages:
NullReferenceException was unhandled by user code.
Object reference not set to an instance of an object.
Can anyone offer some suggestions?
Thanks,
CR Junk
I have a web form that I would like to enhance. What I'd like to do
is this:
A user adds/edits the text in a textbox. I want the adjoining label to
change color.
Example:
User edits text in txtCaseNumber. The cursor leaves txtCaseNumber.
Code executes and turns lblCaseNumber text from black to red.
Here is what I've come up with so far:
Protected Sub txtCaseNumber_TextChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles txtCaseNumber.TextChanged
ChangeLabelColor(sender)
End Sub
Private Sub ChangeLabelColor(ByVal TextBox)
Dim labelID As String = TextBox.ID.replace("txt", "lbl")
Dim ctrl As New Control
Dim ctrlNameText As Label
For Each ctrl In Page.FindControl("aspnetForm").Controls
If TypeOf (ctrl) Is Label And (ctrl.ID.ToString.Trim =
labelID.Trim) Then
ctrlNameText = ctrl
ctrlNameText.ForeColor = Drawing.Color.Red
End If
Next
End Sub
The code bombs out on the For Each ctrl statement.
In debug mode, I'm receiving the following messages:
NullReferenceException was unhandled by user code.
Object reference not set to an instance of an object.
Can anyone offer some suggestions?
Thanks,
CR Junk