Create a new form file named defa4.4.aspx
. CS
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Public partial class default4: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Textbox1.attributes. Add ("onkeydown", "btnclick (this, event );");
Textbox2.attributes. Add ("onkeydown", "btnclick (this, event );");
}
Protected void button#click (Object sender, eventargs E)
{
Alert ("submitted by 1111111111111111111111 ");
}
Protected void button2_click (Object sender, eventargs E)
{
Alert ("submitted by 2222222222222222222222 ");
}
Private void alert (string text)
{
Clientscript. registerstartupscript (this. GetType (), guid. newguid (). tostring (), "alert (\" "+ TEXT +" \ ");", true );
}
}
Page:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default4.aspx. cs" inherits = "default4" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<SCRIPT src = "scripts/jquery-1.4.1.min.js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Function btnclick (OBJ, e ){
If (navigator. appname = "Microsoft Internet Explorer") {// determines the browser;
VaR currkey = 0;
Currkey = event. keycode;
If (currkey = 13 ){
If (OBJ = Document. All. textbox1) {// _ newpwd. ATTR ("ID ")
Document. All. button1.click ();
}
Else {
Document. All. button2.focus ();
Document. All. button2.click ();
}
}
} Else {
VaR currkey = 0;
Currkey = E. Which;
If (currkey = 13 ){
If (OBJ = textbox1 ){
Button1.click ();
}
Else {
Button2.focus ();
Button2.click ();
}
}
}
}
</SCRIPT>
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"/>
<Asp: textbox id = "textbox2" runat = "server"> </ASP: textbox>
<Asp: button id = "button2" runat = "server" onclick = "button2_click" text = "button"/>
</Div>
</Form>
</Body>
</Html>
Copy directly ,,
The following code is used as a server control: When the textbox ID changes, the button ID changes:
Function btnclick (OBJ, e ){
If (navigator. appname = "Microsoft Internet Explorer") {// determines the browser;
VaR currkey = 0;
Currkey = event. keycode;
If (currkey = 13 ){
If (OBJ = Document. All. _ keywords. ATTR ("name") {// _ newpwd. ATTR ("ID ")
Document. All. _ imagebutton1.attr ("name"). Click (); // The attributes ,,,
}
Else {
Document. All. _ imagebutton2.attr ("name"). Focus ();
Document. All. _ imagebutton2.attr ("name"). Click ();
}
}
} Else {
VaR currkey = 0;
Currkey = E. Which;
If (currkey = 13 ){
If (OBJ = _ keywords ){
_ Imagebutton1.click ();
}
Else {
_ Imagebutton2.focus ();
_ Imagebutton2.click ();
}
}
}
}