Wednesday, March 21, 2012

DefaultButton and the ValidationSummary Control

Scenario:

I have an asp:panel control with the defaultbutton attribute set to a button within the panel. The button is part of a validation group that includes a requiredvalidator control associated with a textbox (within the panel). I also have a validationsummary control that is part of the validationgroup and also has its ShowMessageBox attribute set to true. The validation summary displays correctly when I click on the button, but when I hit enter on the keyboard I get the text value of the required validator to show up but the validationsummary popup message does not appear. I posted the code below. Any clues?

<asp:UpdatePanel ID="upCustomerEdit" runat="server">
<ContentTemplate>
<asp:Panel ID="panCustomerEdit" runat="server" DefaultButton="btnSave">
<table>
<tr>
<td>Some label:</td>
<td>
<asp:Textbox ID="Textbox1" runat="server"></asp:DropDownList>
<asp:RequiredFieldValidator ID="valTextbox1" runat="server" ControlToValidate="Textbox1" ValidationGroup="valGroupSave" EnableClientScript="true" Text="*" Display="Static" ErrorMessage="Textbox 1 value is required" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSave" runat="Server" Text="Save" ValidationGroup="valGroupSave" CausesValidation="true" />
</td>
</tr>
</table>
</asp:Panel>
<asp:ValidationSummary ID="valSummary" runat="server"
DisplayMode="BulletList"
ShowMessageBox="True"
ShowSummary="False"
ValidationGroup="valGroupSave"
HeaderText="Errors on Page:" />
</ContentTemplate>
</asp:UpdatePanel>

The exact same problem plagues me also. The ValidationSummary does not show up when the enter key is being pressed.

Has anyone yet found a solution for this one?Sad

sincerely stawrogin


See if this post helps you out at all:http://forums.asp.net/p/985791/1798911.aspx

-Damien


Validation controls, which includes theBaseCompareValidator,BaseValidator,CompareValidator,CustomValidator,RangeValidator,RegularExpressionValidator,RequiredFieldValidator, andValidationSummary control are not compatible with UpdatePanel

http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx

You can download compatible version of validators from here

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx


Thanks for your suggestions. It is not about the UpdatePanel. In fact i don't use an UpdatePanel. It's about the ValidationSummary not being shown.

Take this simple scenario (code below): A Loginform with username, password, and a Login-Button. The defaultFocus is on the username, the defaultButton is set to the Login-button. Additionally there are two RequiredFieldValidators and a ValidationSummary. When clicking the Login-Button all controls get evaluated and the ValidationSummary is being shown. When hitting enter, only the Text of the RequiredFieldValidator is shown but not the ValidationSummary. I want the Validation to be the same whether anyone clicks the button or hits enter. But how?


<form id="form1" runat="server" defaultfocus="txtUserName" DefaultButton="btnLogin">
<div>
<div>
<h2>Login</h2>
</div>
<div>
<asp:Label ID=lblUserName runat=server AssociatedControlID="txtUserName" CssClass="w-117">Benutzername</asp:Label><asp:RequiredFieldValidator ID=reqUser runat=server Text=" *" ControlToValidate="txtUserName" ErrorMessage="Erforderliche Eingabe Benutzername." SetFocusOnError=true></asp:RequiredFieldValidator>
<asp:TextBox id="txtUserName" runat=server CausesValidation=true CssClass="w-153" />
</div>
<div>
<asp:Label ID=lblPassword runat=server AssociatedControlID="txtPassword" CssClass="w-117">Passwort</asp:Label><asp:RequiredFieldValidator ID=requPassword runat=server Text=" *" ControlToValidate="txtPassword" ErrorMessage="Erforderliche Eingabe Passwort." SetFocusOnError=true></asp:RequiredFieldValidator>
<asp:TextBox id="txtPassword" runat=server CausesValidation=true CssClass="w-153" TextMode=Password />
<asp:Button ID=btnLogin runat=server Text="Login" />
</div>
<asp:ValidationSummary ID=valSummaryLogin runat=server DisplayMode=BulletList ShowSummary=true/>
</div>
</form>


I have a similar issue. I have a Validation Summary out side of a GridView that has a Range Validator inside of it. The Range Validator will fire correctly with either pressing "Enter" or clicking the "Update" button (set as DefaultButton). However the Validation Summary will not update when I press "Enter", only when I click on the "Update" button.

Anyone else have an idea?

No comments:

Post a Comment