Multiple text boxes on one page, press enter to submit different event Solutions

Source: Internet
Author: User
Phenomenon: Today met with the same address on the Internet http://www.cnblogs.com/baoposhou/archive/2006/12/29/607419.html
The same problem -- When multiple text boxes on the same page are entered, press enter and submit different event solutions:
[LINK content] I encountered a problem in my work today. I used a user control to create a search box with a list and a text box.
When I drag the user control to the webform, I enter some files in the text box and press enter to find that the page is PostBack, but it does not trigger the searchbutton Processing Event.

The source code of ascx is as follows: : < Div Align = "Center" >
< ASP: dropdownlist ID = "Ddltype" Runat = "Server" > </ ASP: dropdownlist >
< ASP: textbox ID = "Tbxkey" Runat = "Server" Width = "105px" > </ ASP: textbox > & Nbsp;
< ASP: imagebutton ID = "Imgbtnsearch" Runat = "Server" Causesvalidation = "False" Imageurl = "~ /Images/search.gif" > </ ASP: imagebutton >
</ Div >

Asp.net uses the data in viewstate to determine which control triggers the event and then determine the method to handle the call. The above problem should be caused by a carriage return, and the page viewstate does not correctly indicate the control that triggered the event.
Another problem is that there is a web form page. If there are multiple text boxes and multiple buttons, for example, there is a search box and search button on one of our home pages, the member logon box and logon button, the best practice is that when you press enter in the search box, a search is submitted, and a logon event is triggered when you press enter in the username or password box of the member.
As we all know, after a user control is dragged to the Web from, the control name on the user control changes, and one web from can only have one runat server form.
Problem: Enter multiple text boxes on the same page and press enter to solve different event problems.
Analysis can view the HTML of this pageSource codeFile, you can see that the server control has changed to the submit type.
Solution: Add the following function text box to call this
//////////////////
// Press enter to process the event //
//////////////////
Function clickbtn (E)
{
If (window. event. keycode = 13)
{
VaR id = E. ID;
Switch (ID)
{
Case "txt_phonenum ":
Document. getelementbyid ("img_phonenum_search"). Click (); // call the mobile phone number search event
Window. event. returnvalue = false;
Break;
Case "txt_searchname ":
Document. getelementbyid ("imgbtn_search"). Click (); // call the product name search event
Window. event. returnvalue = false;
Break;
}
}
}

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.