大家好,
我有一个问题,想在asp.net页面中,增加一个文本框,并编写获得焦点时的事件 onfocus,不知如何编写?以及这个textbox是用web forms 中的,还是html控件中的?谢谢

解决方案 »

  1.   

    web控件的话可以在formload的事件里写
    TextBox1.Attributes.Add("onfocus", "alert('aaa');");
      

  2.   

    html控件直接在source设计页面里写 比如
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!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">
        <title>Untitled Page</title>
    </head>
    <body id="test1">
        <form id="form1" runat="server">
        <div>
            &nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
            <input  name="t2" type="text" onfocus="alert('a');" />
        </form>
    </body>
    </html>