Using this simple code I have two text boxes, two RequiredFieldValidators with a validation group and display sent to none and a ValidationSummary with ShowMessageBox="True". I also have the default button of the form set.
Run the code, put the focus on the first text box and hit enter--nothing happens.
Run the code, type some text in the second box and hit enter, you get a message saying the fist text box is required.
I think the first RequiredFieldValidator is squashing the event and since its display is none, nothing happens when enter is pressed and the display is none.
How can I stop this and always show a message box?
Sorry, I don't follow. I need to use the validation group to show all validation at the same time and can't use in-line validators because of space considerations.
The ValidationGroup property is only needed for the validation controls and the control that will be used to trigger the postback to the server. Unless you have AutoPostBack set to "true" for your TextBox controls, the ValidationGroup property is unnecessary.
Christopher Reed, MCT, MCPD, MCTS, Microsoft Specialist, MTA
"The oxen are slow, but the earth is patient."
sdavidkyle
0 Points
3 Posts
ValidationSummary not being fired
Apr 24, 2012 06:44 PM|LINK
Using this simple code I have two text boxes, two RequiredFieldValidators with a validation group and display sent to none and a ValidationSummary with ShowMessageBox="True". I also have the default button of the form set.
Run the code, put the focus on the first text box and hit enter--nothing happens.
Run the code, type some text in the second box and hit enter, you get a message saying the fist text box is required.
I think the first RequiredFieldValidator is squashing the event and since its display is none, nothing happens when enter is pressed and the display is none.
How can I stop this and always show a message box?
<form id="form1" runat="server" defaultbutton="btnValidate">
<asp:Label ID="lbl1" runat="server" Text="Text 1:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="Validation"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="TextBox1"
Display="None" ErrorMessage="Text 1 is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblGenderRequired" runat="server" Text="Text 2:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" ValidationGroup="Validation"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
Display="None" ErrorMessage="Text 2 is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="btnValidate" runat="server" Text="Validate Input" ValidationGroup="Validation" />
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="Validation" />
</form>
sriramabi
Contributor
4351 Points
1277 Posts
Re: ValidationSummary not being fired
Apr 24, 2012 07:28 PM|LINK
Change Display="None" to Display="Dynamic" in reqfield validator
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="Text 1 is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator>
and remove ValidationGroup Property in u r textboxes...
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
thank u
sdavidkyle
0 Points
3 Posts
Re: ValidationSummary not being fired
Apr 24, 2012 08:09 PM|LINK
Thanks, but I want the validation group so that there is an alert with all validations at once.
David
sriramabi
Contributor
4351 Points
1277 Posts
Re: ValidationSummary not being fired
Apr 24, 2012 08:21 PM|LINK
K
But its not good...remove Validation="Group" in textBox...
for exambe enter value in textbox time call validationgroup.this time below textbox display empty validation...
the Validation="Group" is call only Validation Summary and button...But u like
thank u
sdavidkyle
0 Points
3 Posts
Re: ValidationSummary not being fired
Apr 24, 2012 09:26 PM|LINK
Sorry, I don't follow. I need to use the validation group to show all validation at the same time and can't use in-line validators because of space considerations.
Careed
All-Star
18798 Points
3649 Posts
Re: ValidationSummary not being fired
Apr 25, 2012 03:18 AM|LINK
The ValidationGroup property is only needed for the validation controls and the control that will be used to trigger the postback to the server. Unless you have AutoPostBack set to "true" for your TextBox controls, the ValidationGroup property is unnecessary.
"The oxen are slow, but the earth is patient."
coolpal9
Member
164 Points
538 Posts
Re: ValidationSummary not being fired
Apr 25, 2012 04:58 AM|LINK
To provide validation summary, it is necessary to provide validation group and give it a name, say 'add' or anything you feel like.
The validation group binds all the validators together. Then add a validation summary.