欢迎来到飞鸟慕鱼博客,开始您的技术之旅!
当前位置: 首页知识笔记正文

点击后禁用按钮 直到操作完成

墨初 知识笔记 57阅读

已经很久没写东西了。今天他把写给同事的一段代码改了一下,分享出来。此代码用于在单击按钮后禁用按钮,直到操作完成。有更好的方法大家一起讨论!%@PageLanguage='C#'%!DOCTYPEhtmlPUBLIC '-//W3C//dtdxhtml 1.0 transitional//EN ' ' ' script runat=' server ' protectedvoidpage _ Load(object sender,EventArgse){btn。属性. add(' onclickpan style=' background-color : rgba(245,245,245,1);color: rgba(0,0,0,1)" ",第页GetPostBackEventReference(btn,' ')'this . value=' submitting this . disabled=true ');lbtn .属性。添加(' onclick '' this。innertext=' Submitting ');this . disabled=true’);ibtn .属性。添加(' onclick

n style="background-color: rgba(245, 245, 245, 1); color: rgba(0, 0, 0, 1)">",
            Page.GetPostBackEventReference (ibtn, 
""+
            
";this.alt='Submitting';this.disabled = true;");

        
//
        // ASP.NET 2.0 above
        //
        //btn.Attributes.Add ("onclick",
        //    ClientScript.GetPostBackEventReference (btn, "") +
        //    ";this.value='Submitting';this.disabled = true;");
        //lbtn.Attributes.Add ("onclick",
        //    "this.innerText='Submitting';this.disabled = true;");
        //ibtn.Attributes.Add ("onclick",
        //    ClientScript.GetPostBackEventReference (ibtn, "") +
        //    ";this.alt='Submitting';this.disabled = true;");
        //
        // OR 
        //
        //btn.OnClientClick =
        //    ClientScript.GetPostBackEventReference (btn, "") + 
        //    ";this.value='Submitting';this.disabled = true;";
        //lbtn.OnClientClick = "this.innerText='Submitting';this.disabled = true;";
        //ibtn.OnClientClick = ClientScript.GetPostBackEventReference (ibtn, "") +
        //    ";this.alt='Submitting';this.disabled = true;";        
    }
    protected 
void btn_Click (object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep (
2000);
        Label1.Text 
= DateTime.Now.ToString ();
    }

    protected 
void lbtn_Click (object sender, EventArgs e)
    {
        LinkButtonClickCount
++;
        System.Threading.Thread.Sleep (
2000);
        Label1.Text 
= "link button:" + DateTime.Now.ToString ()
            
+ "<br/>count:" + LinkButtonClickCount.ToString ();
    }

    protected 
void ibtn_Click (object sender, ImageClickEventArgs e)
    {
        ImageButtonClickCount
++;
        System.Threading.Thread.Sleep (
2000);
        Label1.Text 
= "image button:" + DateTime.Now.ToString ()
            
+ "<br/>count:" + ImageButtonClickCount.ToString ();
    }

    
int LinkButtonClickCount
    {
        get
        {
            object tmp 
= ViewState["LinkButtonClickCount"];
            
return (tmp == null? 0 : (int)tmp;
        }
        set { ViewState[
"LinkButtonClickCount"= value; }
    }
    
int ImageButtonClickCount
    {
        get
        {
            object tmp 
= ViewState["ImageButtonClickCount"];
            
return (tmp == null? 0 : (int)tmp;
        }
        set { ViewState[
"ImageButtonClickCount"= value; }
    }
</script>

<html xmlns="">
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
        
<div>
            
<asp:Button ID="btn" runat="server" Text="What time is it, please!" 
            OnClick
="btn_Click" />
            
<asp:LinkButton ID="lbtn" runat="server" OnClick="lbtn_Click">
        What time is it, please!
</asp:LinkButton>
            
<asp:ImageButton ID="ibtn" runat="server" 
              AlternateText
="What time is it, please!"
              Height
="30px" OnClick="ibtn_Click" 
              ImageUrl
="" 
            
/>
            
<br />
            
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        
</div>
    
</form>
</body>
</html>


标签:
声明:无特别说明,转载请标明本文来源!