On the ASPX page, press enter in different text boxes to execute the server Click Event of Different buttons (browser compatibility, Firefox browser)

Source: Internet
Author: User

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 ();

}
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.