gridview and custom validator problem

A

André Freitas

i got a gridview with a customvalidator for a textbox.
the textbox default value is empty, and im validating on empty too.

the problem is when im trying to add the item, the validator is firing for
all the rows in the gridview, and not only the one that im trying to add.

im using:

<asp:TemplateField HeaderText="MOTIVO">
<ItemTemplate>
<asp:TextBox ID="oReason" runat="server" />
<asp:CustomValidator ID="voReason" runat="server"
ControlToValidate="oReason"
EnableClientScript="False"
SetFocusOnError="True"
ErrorMessage="Motivo inválido. O campo deve ter no mínimo 5
caracteres."
OnServerValidate="Validating"
ValidateEmptyText="True"
Display="None" />
</ItemTemplate>
</asp:TemplateField>

Protected Sub Validating(ByVal sender As Object, ByVal e As
ServerValidateEventArgs)

Dim vCustomValidator As CustomValidator
vCustomValidator = DirectCast(sender, CustomValidator)

Dim vGridViewRow As GridViewRow
vGridViewRow = vCustomValidator.NamingContainer

Dim vTextBox As TextBox
vTextBox = vGridViewRow.FindControl("oReason")
e.IsValid = ValidateText(vTextBox.Text, ReasonPattern)
vTextBox.Dispose()

End Sub
 

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
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top