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

来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:48 点击:

最近碰到一个问题:页面使用了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";
    }

 

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


摘自  寂寞沙洲
 
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • 浅析.NET下XML数据访问新机制
    • asp.net 面试+笔试题目第1/2页
    • C# 邮件地址是否合法的验证
    • asp.net 设置GridView的选中行的实现代码
    • C#高级编程:数据库连接[1]
    • 经典C++程序1
    • IIS 自动回收导致后台定时器失效的问题解决
    • ASP.NET&#160;GridView列表代码示例
    • Asp.net MVC源码分析--Action Filter的链式调用
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1