Home All Groups Group Topic Archive Search About

custom validator and button events

Author
11 Apr 2005 2:09 PM
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

Author
11 Apr 2005 2:53 PM
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?

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> 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
Are all your drivers up to date? click for free checkup

Author
12 Apr 2005 6:27 AM
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.


Show quoteHide quote
> 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?
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
Author
12 Apr 2005 3:27 PM
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.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Bookmark and Share