when Hou I put the user control onto the WebForm above, enter some random file on a text box, directly enter, the page is found PostBack, but did not lead the process events SearchButton.
ascx source as follows :
< asp:dropdownlist id ="ddlType" runat ="server" ></ asp:dropdownlist >
< asp:TextBox id ="tbxKey" runat ="server" Width ="105px" ></ asp:TextBox >
< asp:imagebutton id ="imgbtnSearch" runat ="server" CausesValidation ="False" ImageUrl ="~/images/search.gif" ></ asp:imagebutton >
</ DIV >
asp.net is judged by the data in the ViewState Control which triggered the event, and then determine the treatment method call. The above problems should be carriage return, page ViewState There is no indication right trigger control events caused.
Another problem is that a web form page, if there are multiple text boxes, multiple button, for example, we have a search box and search button on the home page, members login box and login button, the user is best achieved when Enter the search box, the search is submitted, when the carriage return on your membership user name or password box is logon events.
Earth people know, after the user controls onto the web from, control name will be changed on the user control, and they can only have a web from a Form runat server's. In this case, after some modifications, the control code is changed to the user as follows:
the ascx revised code:
< DIV align ="center" onkeypress ="javascript:SubmitSearch()" >< asp:dropdownlist id ="ddlType" runat ="server" ></ asp:dropdownlist >
< asp:TextBox id ="tbxKey" runat ="server" Width ="105px" ></ asp:TextBox > <asp:imagebutton id="imgbtnSearch" runat="server" CausesValidation="False" ImageUrl="~/images/search.gif"></asp:imagebutton></DIV><script language="javascript">function SubmitSearch(){if(window.event.keycode eleId were{)13==
= event.srcElement.id;
if(eleId.indexOf('tbxKey') > 0){
var btnId = eleId.substring(0, eleId.indexOf('tbxKey')) + 'imgbtnSearch';
document.getElementById(btnId).click();
}
}
}
</ script >
< input style ="display:none" />
At this point, no matter where the user controls pulled the search box, just hit enter on the text box, the box will be able to submit this search.
But bearing in mind that there is no <input style = "display: none" /> This part will not succeed, do not know why, huh, huh. (Internet search, I also have a friend who raised the issue, but no answer), I practice what is wrong, please correct me, thank you!
Reproduced in: https: //www.cnblogs.com/baoposhou/archive/2006/12/29/607419.html