There is a search input box in the Header. The search Button is the Button control, which is also used in the custom control of "news article search.
Stop the focus in the "News Title or content" input box, press enter, but the corresponding content is the content of the input box in the Header.
Cause: Press enter to execute the first submit button on your page. Solution: (the following uses the information search input box as an example)
1. js:
----------------------------------------------------------------------------
/* Press enter and execute the button */
Function SubmitKeyClick (button ){
If (event. keyCode = 13 ){
Event. keyCode = 9;
Event. returnValue = false;
Document. all [button]. click ();
}
}
Function checkinputbox (){
Var charBag = "[^ '~ @ # $ % ^ &/'| *] ";
Var searchkey = document. getElementById ("ArticleSearch1_txtSearchKey ");
If (trim (searchkey. value). length = 0 | trim (searchkey. value). length> 30 ){
Alert ("the keyword of the news article cannot be blank or the length cannot exceed characters! ");
Searchkey. focus ();
Return false;
}
If (trim (searchkey. value )! = ""){
For (var I = 0; I <searchkey. value. length; I ++ ){
Var c = searchkey. value. charAt (I );
If (charBag. indexOf (c)>-1 ){
Alert ("the keyword string for searching news articles contains illegal characters (" + c + ")! ");
Searchkey. focus ();
Return false;
}
}
}
}
2. aspx page controls:
---------------------------------------------------
<Input id = "txtSearchKey" name = "txtSearchKey" type = "text" runat = "server" maxlength = "30" onfocus = "this. select ();"/>
3. cs:
---------------------------------------------------
This.txt SearchKey. Attributes. Add ("onkeyPRess", "SubmitKeyClick ('articlesearch1 _ btnsearch ');");
This. btnSearch. Attributes. Add ("onclick", "return checkinputbox ();");
In cs of the Header, add the Attributes attribute of the input box.
This.txt Key. Attributes. Add ("onkeypress", "SubmitKeyClick ('header1 _ btnsearchkey ');");