custom validator and button events

A

Ant

Hi,
I have a program with a textbox, customvalidator and button.
<asp:TextBox ID="txtName" Runat="server" MaxLength="30"
AutoPostBack="True" CausesValidation="True"></asp:TextBox>
<asp:CustomValidator ID="CVltxtNombre" Runat="server"
ControlToValidate="txtName" Display="Dynamic"
OnServerValidate="CVltxtNombre_ServerValidate"asp:CustomValidator>
<asp:Button ID="btnGo" Runat="server" Text="Go" OnClick="btnGo_Click"
/>
I want to save in Database the textbox.text. If I want to modify one
database record, I get the record and put it in the textbox. When I
change the textbox.text and press button go, goes to
CVltxtNombre_ServerValidate event because it has been a change. But
after this it doesn't go to btnGo_Click event. Why? If Page.IsValid is
true, why doesn't it go to Button event?
Can any help me?? I'm using .NET 2005 beta 1
 
B

Brock Allen

Just so you know, your button event should get called always, even if Validation
fails. IN the Button event you should always check IsValid before writing
data to the database.

Do you submit by clicking the button or by pressing enter on the form?
 
A

Ant

Hi Brock. Thanks for answering. I have this custom validator event:
Sub CVltxtNombre_ServerValidate(ByVal source As Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs)
Try
If .... Then
End If
Catch ex As Exception
args.IsValid = False
txtNombre.Focus()
End Try
End Sub

I have a button event:
Sub btnGo_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
If Page.IsValid Then
Insert()
End If
End Sub
When I change de textbox.text and click button, program goes FIRST to
CVltxtNombre_ServerValidate because it has been a change in the
textbox and then doesn't go to btnGo_Click event (Page is valid). I
don't know why button event is not been called. I want submit by
clicking the button.
Thanks again.
 
B

Brock Allen

When I change de textbox.text and click button, program goes FIRST to
CVltxtNombre_ServerValidate because it has been a change in the
textbox and then doesn't go to btnGo_Click event (Page is valid). I
don't know why button event is not been called. I want submit by
clicking the button.

The Validator should always get called. So should your button. I'm not sure
why it's not getting called.
 

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

No members online now.

Forum statistics

Threads
474,144
Messages
2,570,823
Members
47,369
Latest member
FTMZ

Latest Threads

Top