Enter user control problem to solve submitted

One problem encountered in work today, I make use of user controls a search box that comes with a down list and a text box
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 :
None.gif < DIV  align ="center" >
None.gif
< asp:dropdownlist  id ="ddlType"  runat ="server" ></ asp:dropdownlist >
None.gif
< asp:TextBox  id ="tbxKey"  runat ="server"  Width ="105px" ></ asp:TextBox > &nbsp;
None.gif
< asp:imagebutton  id ="imgbtnSearch"  runat ="server"  CausesValidation ="False"  ImageUrl ="~/images/search.gif" ></ asp:imagebutton >
None.gif
</ 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:

ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Control Language="c#" AutoEventWireup="false" Codebehind="Search.ascx.cs" Inherits="Dots.CMS.Web.module.Search" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"  %>
None.gif
< DIV  align ="center"  onkeypress ="javascript:SubmitSearch()" >< asp:dropdownlist  id ="ddlType"  runat ="server" ></ asp:dropdownlist >
None.gif
< 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==
None.gif

ExpandedBlockStart.gifContractedBlock.gif
dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
= event.srcElement.id;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if(eleId.indexOf('tbxKey') > 0)dot.gif{
InBlock.gif                
var    btnId = eleId.substring(0, eleId.indexOf('tbxKey')) + 'imgbtnSearch';
InBlock.gif                document.getElementById(btnId).click();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif
</ script >
None.gif
< 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.emteeth.gif

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

Guess you like

Origin blog.csdn.net/weixin_34162228/article/details/93320499