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
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