当前位置:编程学习 > asp >>

AJAX回传过程中禁止用户重复提交

最近碰到一个问题:页面使用了Ajax,非jQuery,用的是微软的ScriptManager和UpdateProgress。如何在数据回传过程中禁止用户重复提交?即用户点了提交按钮后,按钮不能用,等到数据回传后,按钮状态自动变为可用!

到微软的论坛上去问了,高手给出了答案。经测试,下面的方法可行!

前台页面:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel runat="server" ID="UpdatePanel1">
        <ContentTemplate>

         <asp:Button Text="提交" ID="btn_Go" runat="server" onclick="btn_Go_Click"   />
        </ContentTemplate>

    </asp:UpdatePanel>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
                <ProgressTemplate>
                    <img alt="" src="Images/Loading1.gif" style="width: 32px; height: 32px" />正在处理……
                </ProgressTemplate>
            </asp:UpdateProgress>
    </form>

后台代码:

    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager.RegisterOnSubmitStatement(Page, typeof(Page), "Go_disabled", "document.getElementById('btn_Go').disabled='disabled';");
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "Clear_disabled", "document.getElementById('btn_Go').disabled='';", true);

    }
    protected void btn_Go_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);//模拟任务
        //for (long i = 1; i < 1000000000; i++) ;
        btn_Go.Text = "execute complete";
    }

 

拣尽寒枝不肯栖,寂寞沙洲冷。 


摘自  寂寞沙洲
 
补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,