K
Kieran
Hi, am new to ASP.NET, so be gentle with me!
I have:
2 x TextBox
2 x CustomValidators
1 x ValidationSummary
Both TextBox's have AutoPostBack and CausesValidation set to True.
ValidationGroup is not set.
Both CustomValidators have EnableClientScript set to False, and
ValidateEmptyText set to True. ValidationGroup is not set.
ControlToValidate is set to the appropriate TextBox, and
onServerValidate points to the appropriate code behind function.
ValidationSummary has EnableClientScript and ShowMessageBox set to
False, and ValidationGroup is not set. ShowSummary is set to True.
The onServerValidate functions are identical, in that they set
args.IsValid to False, if args.Value.ToString().Length == 0, otherwise
args.IsValid is set to True.
There is no button to explicitly Postback. The TextBox AutoPostBack is
used for this when tabbing out of the textbox.
If I enter text into TextBox1, and tab out, then the correct error for
an empty TextBox2 is displayed. If I then enter text for TextBox2, so
both textboxes have values,and tab out, then no errors are displayed.
If I then blank out TextBox1, and tab out, an error for TextBox1 is
displayed. If I then blank out TextBox2, so that *both* textboxes are
empty, ***no error is displayed***. Huh? What am I not understanding
here? And, yes, before anyone mentions it, I am aware of the
RequiredFieldValidator, but don't wish to use it in this instance.
Thanks in advance,
Kieran
The following is the relevant designer source:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
CausesValidation="True"
style="z-index: 1; left: 245px; top: 65px; position:
absolute"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
CausesValidation="True"
style="z-index: 1; left: 245px; top: 95px; position:
absolute"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1" Display="None"
EnableClientScript="False"
ErrorMessage="TextBox1 is empty"
onservervalidate="CustomValidator1_ServerValidate"
style="z-index: 1; left: 10px; top: 65px; position: absolute;
width: 190px"
ValidateEmptyText="True"></asp:CustomValidator>
<asp:CustomValidator ID="CustomValidator2" runat="server"
ControlToValidate="TextBox2" Display="None"
EnableClientScript="False"
ErrorMessage="TextBox2 is empty"
onservervalidate="CustomValidator2_ServerValidate"
style="z-index: 1; left: 10px; top: 95px; position: absolute;
width: 190px"
ValidateEmptyText="True"></asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
style="z-index: 1; left: 245px; top: 130px; position:
absolute; height: 38px; width: 435px"
EnableClientScript="False" />
And below are the two identical CustomValidator functions:
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = (args.Value.ToString().Length == 0) ?
false : true;
}
protected void CustomValidator2_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = (args.Value.ToString().Length == 0) ?
false : true;
}
I have:
2 x TextBox
2 x CustomValidators
1 x ValidationSummary
Both TextBox's have AutoPostBack and CausesValidation set to True.
ValidationGroup is not set.
Both CustomValidators have EnableClientScript set to False, and
ValidateEmptyText set to True. ValidationGroup is not set.
ControlToValidate is set to the appropriate TextBox, and
onServerValidate points to the appropriate code behind function.
ValidationSummary has EnableClientScript and ShowMessageBox set to
False, and ValidationGroup is not set. ShowSummary is set to True.
The onServerValidate functions are identical, in that they set
args.IsValid to False, if args.Value.ToString().Length == 0, otherwise
args.IsValid is set to True.
There is no button to explicitly Postback. The TextBox AutoPostBack is
used for this when tabbing out of the textbox.
If I enter text into TextBox1, and tab out, then the correct error for
an empty TextBox2 is displayed. If I then enter text for TextBox2, so
both textboxes have values,and tab out, then no errors are displayed.
If I then blank out TextBox1, and tab out, an error for TextBox1 is
displayed. If I then blank out TextBox2, so that *both* textboxes are
empty, ***no error is displayed***. Huh? What am I not understanding
here? And, yes, before anyone mentions it, I am aware of the
RequiredFieldValidator, but don't wish to use it in this instance.
Thanks in advance,
Kieran
The following is the relevant designer source:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
CausesValidation="True"
style="z-index: 1; left: 245px; top: 65px; position:
absolute"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
CausesValidation="True"
style="z-index: 1; left: 245px; top: 95px; position:
absolute"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1" Display="None"
EnableClientScript="False"
ErrorMessage="TextBox1 is empty"
onservervalidate="CustomValidator1_ServerValidate"
style="z-index: 1; left: 10px; top: 65px; position: absolute;
width: 190px"
ValidateEmptyText="True"></asp:CustomValidator>
<asp:CustomValidator ID="CustomValidator2" runat="server"
ControlToValidate="TextBox2" Display="None"
EnableClientScript="False"
ErrorMessage="TextBox2 is empty"
onservervalidate="CustomValidator2_ServerValidate"
style="z-index: 1; left: 10px; top: 95px; position: absolute;
width: 190px"
ValidateEmptyText="True"></asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
style="z-index: 1; left: 245px; top: 130px; position:
absolute; height: 38px; width: 435px"
EnableClientScript="False" />
And below are the two identical CustomValidator functions:
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = (args.Value.ToString().Length == 0) ?
false : true;
}
protected void CustomValidator2_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = (args.Value.ToString().Length == 0) ?
false : true;
}