DefaultButton and the ValidationSummary Control RRS feed

  • Question

  • User1032812968 posted


    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">
            <asp:Panel ID="panCustomerEdit" runat="server" DefaultButton="btnSave">
                                    <td>Some label:</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 colspan="2">
                            <asp:Button ID="btnSave" runat="Server" Text="Save" ValidationGroup="valGroupSave" CausesValidation="true" />
            <asp:ValidationSummary ID="valSummary" runat="server"
                HeaderText="Errors on Page:" />

    Wednesday, April 18, 2007 4:52 PM

All replies

  • User-1690838931 posted

    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? [:(] 


    sincerely stawrogin 

    Tuesday, August 21, 2007 8:06 AM
  • User923504599 posted

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


    Tuesday, August 21, 2007 8:20 AM
  • User-1690838931 posted

    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">
                    <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" />
                    <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" />
                <asp:ValidationSummary ID=valSummaryLogin runat=server DisplayMode=BulletList ShowSummary=true/>

    Wednesday, August 29, 2007 7:09 AM
  • User1246221937 posted

    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?

    Wednesday, December 12, 2007 9:30 AM
  • User2021261141 posted

    After a more detailed study of the problem revealed that the construction 
    <Asp: Panel ID = "Panel1" runat = "server" DefaultButton = "btnFind"> 
    <div id="ctl00_cphMain_Panel1" onkeypress="javascript:return WebForm_FireDefaultButton(event,'ctl00_cphMain_btnFind')"> 
    But unfortunately, JavaScript onkeypress event of input field overridden by validator that controlling this field. So when you enter the wrong information and pressing the Enter button it's triggered validator, which displays the text of the error and stops processing events. 
    So that would overcome this "evil" enough to use a different event. In this case, it will keydown.It will look like this: 

    pnlAsset.Attributes.Add ( "onkeydown", "javascript: return WebForm_FireDefaultButton (event, '" + btnFind.ClientID + "')");

    Friday, December 4, 2009 8:25 AM
  • User532034571 posted

    Hi Igon,

    Great, your suggestion is working properly. I would like to add some few things for this. Some of them may have problems with browser capability. In this case, it's better to use below method for "Enter key submit option" and then you can add this JavaScript to the div section.


    protected void Page_Load(object sender, EventArgs e)


            if (!Page.IsPostBack)


                form1.Attributes.Add("onkeydown", "javascript: return WebForm_FireDefaultButton (event, '" + ButtonName.ClientID + "')");

                ClientScript.RegisterHiddenField("__EVENTTARGET", "ButtonName");



    // Then use below code.


    <div id="inputArea" onkeypress="javascript:return WebForm_FireDefaultButton(event,'ButtonName')">

    This has been solved the Validation Summary display issue on enter key submit

    Friday, January 14, 2011 9:33 AM