CustomValidator inside a DetailsView

P

Paulo Costa

Hi,

I have, in a webform, a DetailView with 8 fields, 4 of them are required and
I'm using a RequiredValidator with no problems, the other 4 must be all empty
or all filled (cannot be some empty and other filled). To validate this I'm
using a CustomValidator but with no sucess:
- the event defined in the attribute OnServerValidate="OnValidateOverride"
is not triggered;
- the clientside function defined in the attribute
ClientValidationFunction="GradeValidate" is triggered but in javascript i
can´t reach the controls inside DetailsView template fields;

if the textboxs and Validators are outside de Detailsview it works fine.
Can someone give me a clue?
Thanks in advance,

Example:
aspx:
<script type="text/javascript" language="javascript">
function TestValidate(source, args)
{
var obj = document.getElementById("<%=TestDetailsView.ClientID%>");
..........
//the TestDetailsView is reached but the controls inside are not
}
</script>

...............

<asp:TextBox ID="TextBox1" runat="server"/>
<asp:TextBox ID="TextBox2" runat="server"/>
<asp:CustomValidator ID="CustomValidatorTeste1" runat="server"
OnServerValidate="OnValidateOverride" ClientValidationFunction="TesteValidate"
ControlToValidate="TextBox1" ValidationGroup="testeGroup"
ErrorMessage="Obrigatório preencher os restantes campos de override"/>
<asp:CustomValidator ID="CustomValidatorTeste2" runat="server"
OnServerValidate="OnValidateOverride" ClientValidationFunction="TesteValidate"
ControlToValidate="TextBox2" ValidationGroup="testeGroup"
ErrorMessage="Obrigatório preencher os restantes campos de override"/>
<asp:LinkButton ID="InsertBtn" runat="server" Text="Testar"
ValidationGroup="testeGroup" />

codebehind:
public void OnValidateOverride(object sender, ServerValidateEventArgs e)
{
e.IsValid = ((this.TextBox1.Text != string.Empty && this.TextBox2.Text !=
string.Empty) ||
(this.TextBox1.Text == string.Empty && this.TextBox2.Text ==
string.Empty));
}
 

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,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top