The example in this article tells you about ASP.net's Ajax-based enter key submission. Share to everyone for your reference, specific as follows:
Recently encountered a enter key problem, summed up:
1. First review the HTML form of the response to enter, different browsers on enter processing slightly different, here using IE7
A. HTML form has only one textbox, no submit button, click Enter to submit form.
B. >1 textbox, no Submit button, click Enter, form does not respond.
C. Page has one (or more) Submit button, click Enter, trigger the first submit button click.
2. Enter key in asp.net
ASP.net 2.0 provides the DefaultButton property on the form.
Copy Code code 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
The local refresh of Ajax destroys the DefaultButton implementation.
A. ASP. NET's DefaultButton implementation.
Add the Webform_firedefaultbutton method to the HTML.
Copy Code code 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 = &&!) ( 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 does not update back false, causing the default button to fail.
C. Solutions
The same, set yourself
Copy Code code as follows:
I hope this article will be helpful to everyone asp.net order design.