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;
}
}
}