转载

一、测试代码:

1、aspx:

<%@ 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 >
    <title>Untitled Page</title>

    <script type="text/javascript">
    function disableObject(obj)
    {
        obj.disabled = true;
    }
    </script>
   
</head>
<body>
    <form >
    <div>
        <input type="button"
            onserverclick="btn_html_serverclick" />
            <br />
        <asp:Button ID="btn_standard" Text="btn_standard" runat="server" OnClientClick="disableObject(this);" OnClick="btn_standard_Click"
             />
    </div>
    </form>
</body>
</html>

2、cs:
 

 protected void btn_html_serverclick(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
        Response.Write("actions of btn_html_serverclick");
    }

    protected void btn_standard_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
        Response.Write("actions of btn_standard");
    }

备注:以上代码中“System.Threading.Thread.Sleep(3000);”的用意是为了避免按钮事件的执行时间太短、页面刷新太快时用脚本修改的按钮状态无法体现。

二、结论:

standard button脚本修改其disabled属性后,其服务器端事件将不再执行;而html button脚本修改其disabled属性后,其服务器端事件仍将会执行。

这一点会为我们在standard button与html button之间进行取舍时提供些依据。

相关文章:

  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-12-04
  • 2021-05-07
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
相关资源
相似解决方案