responding to changed text doesn't always work

G

Guest

Private Sub txtLastName_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtLastName.TextChanged
If Me.cmdAction.Text = "Update" Then
Me.cmdAction.Enabled = True
End If
End Sub

The above code seems like it should work but doesn't.

The effect I'm trying to get is to prevent a user from clicking an "update"
button unless the user actually changes anything... so the button is supposed
to stay disabled as long as nothing has changed - but as soon as it changes -
I'd like the button to be available again.

Do I need to consider the IsPostback property to get this to work properly?
 
G

Guest

Private Sub txtLastName_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles txtLastName.TextChanged
If Me.cmdAction.Text = "Update" Then
Me.cmdAction.Enabled = True
End If
End Sub

The above code seems like it should work but doesn't.

The effect I'm trying to get is to prevent a user from clicking an
"update" button unless the user actually changes anything... so the
button is supposed to stay disabled as long as nothing has changed -
but as soon as it changes - I'd like the button to be available again.

In this case you wouldn't use the TextChanged event - it's only fired on
postback.

You should use a RequiredFieldValidator - this will prevent the update
button from being clicked - tho you should also write a server side event
handler in case the user has javascript disabled.

If you need more flexiblity, you can write custom javascripts to interact
with the built in .NET validators.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top