ASP.NET Validation Summary Control and Enter key Submit

When you use enter key to sumbit data the validation controls are working properly but most of the time the validation summary not fired as a part of the validation. To over come this problem you can include some JavaScript code in the form or div section of the ASP.NET form. How to get enter key to submit data while avoiding validation summary problem.

protected void Page_Load(object sender, EventArgs e)

{

          if (!Page.IsPostBack)

          {

                   // Add new attribute to form1 event to fire when enter key submit button click event

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

                  // Allow you to use enter key for sumbit data

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

          }

}

 // Add this code to div section on the form1 ASPX page.

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

You can modify this code using JavaScript to select different keys to submit data. But this is the best way to avoid validation summary display issue on ASP.NET.
 
Hope this helps

7 Comments

Comments have been disabled for this content.