In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to solve the problem of ASP.NET enter key submission based on Ajax". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Recently encountered an Enter key problem, to sum up:
1. First of all, review the response of html form to Enter. Different browsers handle Enter slightly differently. IE7 is used here.
A. html form has only one TextBox and no submit button. Click Enter to submit form.
B. > 1 TextBox, no submit button, click Enter, form does not respond.
c. The page has one (or more) submit buttons, click Enter, and trigger the first submit button click.
2. Enter key in ASP.NET
ASP.NET 2. 0 provides the defaultbutton attribute on form.
The copy code is as follows:
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 implementation of defaultbutton.
A. the implementation of defaultbutton of ASP.NET.
Add the WebForm_FireDefaultButton method to the html.
The copy code is as follows:
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 default button to fail.
c. Solution.
If it is different, set it yourself.
The copy code is as follows:
_ _ defaultFired=false
This is the end of the content of "how to solve the problem of ASP.NET enter key submission based on Ajax". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.