ASP. NET Ajax-based Enter key submission problem analysis,

Source: Internet
Author: User

ASP. NET Ajax-based Enter key submission problem analysis,

This example describes ASP. NET Ajax-based Enter key submission. We will share this with you for your reference. The details are as follows:

Recently I encountered a problem with the Enter key, which is summarized below:

1. First, review the html form's response to Enter. Different browsers have slightly different processing requirements for Enter. Here, IE7 is used.

A. html form has only one TextBox without the submit button. Click Enter to submit form.
B.> 1 TextBox. There is no submit button. Click Enter and form has no response.
C. The page has one or more submit buttons. click Enter to trigger the first submit button click.

2. Enter key in ASP. NET

ASP. NET 2.0 provides the defaultbutton attribute on form.
Copy codeThe Code is as follows: <form id = "form" runat = "server" defaultbutton = "dummyDefaultBtn">

3. defaultbutton under Master page.

Set in Page_Load in page

protected void Page_Load(object sender, EventArgs e){  if (!this.Page.IsPostBack)  {   this.Page.Master.Page.Form.DefaultButton = this.BtnSave.UniqueID;

4. defaultbutton under Ajax

Partial Ajax refreshing destroys the defaultbutton implementation.

A. Implementation of ASP. NET defaultbutton.

Add the WebForm_FireDefaultButton method to html.
Copy codeThe Code is as follows: <form name = "aspnetForm" method = "post" action = "" onsubmit = "javascript: return WebForm_OnSubmit ();" onkeypress = "javascript: return WebForm_FireDefaultButton (event, '<your btnID>') "id =" aspnetForm ">

Implementation of WebForm_FireDefaultButton:

var __defaultFired = false;function WebForm_FireDefaultButton(event, target) { if (!__defaultFired && event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {  var defaultButton;  if (__nonMSDOMBrowser) {   defaultButton = document.getElementById(target);  }  else {   defaultButton = document.all[target];  }  if (defaultButton && typeof(defaultButton.click) != "undefined") {   __defaultFired = true;   defaultButton.click();   event.cancelBubble = true;   if (event.stopPropagation) event.stopPropagation();   return false;  } } return true;}

B. The problem is that the js Variable _ defaultFired in Ajax will not be updated back to false, causing the default button to become invalid.

C. Solution

Different from each other. Set it by yourself.
Copy codeThe Code is as follows: __defafirefired = false;

I hope this article will help you with asp.net sequence design.

Articles you may be interested in:
  • ASP. NET2.0 uses the Enter Key as the default submit problem analysis (with source code)
  • Asp.net textbox javascript implements enter and ctrl + enter interchange text boxes to send messages and line breaks (similar to QQ)
  • Download asp.net (c #) Enterprise Library 3.0
  • Brief Introduction to ASP. Net Request Response Process
  • Asp.net implements the method of canceling the Enter response in the text input box of the page form

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.