问题很简单,我在一个页面内有多个textbox 和多个button
我希望在向textbox_a中写完数据后,按回车,button_a响应,在向textbox_b中写完数据后,按回车,button_b响应,
我知道这个问题很弱质,希望大家不吝赐教。

解决方案 »

  1.   

    if(textbox_a)
    {
    textbox_a.Attributes.Add("onkeydown", "if(event.keyCode==13){document.all.button_a.focus();document.all.button_a.click();}");
    }
    else if(textbox_b)
    {
    textbox_b.Attributes.Add("onkeydown", "if(event.keyCode==13){document.all.button_b.focus();document.all.button_b.click();}");
    }
      

  2.   

    不是很弱
    是很复杂(不是难)
    你这样的关系是
    TextBoxb.onchange------->Enter.onKeyDown------>Button.Onclick
      

  3.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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 id="Head1" runat="server">
      <title></title>
    </head>
    <body style="text-align: center">
        <form id="form1" runat="server">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" CommandName="a"  Text="Button" OnClick="Button1_Click" />
        <br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button2" runat="server" CommandName="b"  Text="Button" OnClick="Button2_Click" />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </form>  
    </body>
    </html>using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class Default2 : System.Web.UI.Page
    {    protected void Page_Load(object sender, EventArgs e)
        {        TextBox1.Attributes.Add("onkeydown ", "if(event.keyCode==13){document.all.Button1.focus();document.all.Button1.click();} ");
            TextBox2.Attributes.Add("onkeydown ", "if(event.keyCode==13){document.all.Button2.focus();document.all.Button2.click();} ");
            if (!IsPostBack)
            {
            }
        }    protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = TextBox1.Text.ToString();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            Label1.Text = TextBox2.Text.ToString();
        }
    }
      

  4.   

    老大,谢谢你,真的可以实现。我在我的主页上放了两个用户控件。 其中一个是搜索。另一个是用户登录。 搜索里面有TextBox和Button,用户登录里也有。在单独的页面上时,你的那个方法可以实现。但是为什么放到控件里,就不行了?为什么? 明白我说的意思吗?
      

  5.   

    为什么中间要搞了button反映???可以去掉这个反映
      

  6.   

    TextBox1.Attributes.Add("onkeydown ", "if(event.keyCode==13){document.all.Button1.focus();document.all.Button1.click();} ");就是说向TextBox1添加一个属性,当引发onkeydown事件的时候,判断if(event.keyCode==13)的话
    就{document.all.Button1.focus();document.all.Button1.click();} document.all.Button1.focus();  什么意思?定焦点?
    document.all.Button1.click();  引发Button1的click()事件?不知道我有没有误解
      

  7.   

    我在我的主页上放了两个用户控件。   其中一个是搜索控件(search.ascx)。另一个是用户登录控件(logon.ascx)。   搜索里面有TextBox和Button,用户登录里也有。这两个控件都放在index.aspx里。当我在登录里填上登录信息(用户名,密码),然后回车。搜索控件中(search.ascx)的Button就响应了。转到了搜索页面。我不知道大家明白我的意思吗?
      

  8.   

    帮忙了,我想在输入登录信息后,回车能够跳到登录页面。就是logon.ascx中的那个Button能够响应就行。
      

  9.   

    在页面内添加了<script language=javascript>
    function getfouce()
    {
    if(event.keyCode==13)
    {
    document.all("<%=Button1.ClientID%>").focus();
    document.getElementById("<%=Button1.ClientID%>").click();
    }
    }
    </script>
    然后就行了,好像道理一样。总算完成了