asp.net,所有客户端事件都可以转化成服务器端事件,最简单的方式就是,在客户端事件中调用一个隐藏的按钮(button)的OnClick事件。

需要注意的是,隐藏服务器控件Button,不能用visible=false,只能用style="display:none",否则客户端html页面里看不到这个控件。

前台代码:

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" onblur="document.getElementById('Button1').click();"></asp:TextBox>
        <asp:Button ID="Button1"
            runat="server" Text="Button"  onclick="Button1_Click" style="display:none" />

后台代码:

protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "great!";
    }

  

posted on 2012-09-29 10:16  particle  阅读(627)  评论(0)    收藏  举报