假设1个aspx页面上有2个TextBox 2个DropDownList  我想知道这4个控件中 那个控件获得了焦点.请问这个问题如何解决?谢谢!

解决方案 »

  1.   

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript">
        function focuswhat(obj)
        {
            //debugger;
            document.getElementById("Label1").innerText=obj.id;
        }
        
        </script>
    </head>
    <body scroll=yes>
        <form id="form1" runat="server">
        <div>
        
            <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value=1>1</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:DropDownList ID="DropDownList2" runat="server">
            <asp:ListItem Value=2>2</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <asp:Label ID="Label1" runat="server" Text="Label" Width="78px"></asp:Label></div>
        </form>
    </body>
    </html>
    protected void Page_Load(object sender, EventArgs e)
    {
        this.TextBox1.Attributes.Add("onfocus", "focuswhat(this);");
        this.TextBox2.Attributes.Add("onfocus", "focuswhat(this);");
        this.DropDownList1.Attributes.Add("onfocus", "focuswhat(this);");
        this.DropDownList2.Attributes.Add("onfocus", "focuswhat(this);");
    }