防止 LinkBut​​ton 在 UpdatePanel 内双击

发布于 2024-10-05 10:56:16 字数 176 浏览 3 评论 0原文

我在 UpdatePanel 中有一个 LinkBut​​ton,我不希望客户端在 UpdatePanel 刷新其内容之前单击多次。现在,链接按钮会为每次客户端点击启动部分回发,直到更新面板有时间刷新。这个特定的链接会启动一个非常昂贵的进程,我不想不必要地运行它。是否有 .NET 标准方法可以做到这一点?对此有什么好的解决方案吗?谢谢。

I have a LinkButton inside an UpdatePanel that I do not want the client to click more than once before the UpdatePanel refreshes its contents. Right now the link button initiates a partial postback for every client side click until the update panel has time to refresh. This particular link fires off a very expensive process which I'd rather not have run unnecessarily. Is there a .NET standard way of doing this? Whats a good solution for this? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

清引 2024-10-12 10:56:16

使用 UpdatePanelAnimationExtender。可用于创建良好的体验并阻止进一步的交互,直到更新面板完成。将此与 DGH 的服务器端布尔值结合起来,以防止用户刷新页面并再次提交(将布尔值存储在会话状态中)。

有关 UpdatePanelAnimationExtender 的更多信息,请访问:

https://github.com/DevExpress/AjaxControlToolkit/维基/UpdatePanelAnimation

Use an UpdatePanelAnimationExtender. Can be used to create a nice experience and prevent further interaction until the update panel has finished. Combine this with DGH's server side boolean to prevent a user from refreshing the page and submitting again (store the boolean in Session State).

More information about the UpdatePanelAnimationExtender can be found here:

https://github.com/DevExpress/AjaxControlToolkit/wiki/UpdatePanelAnimation

椒妓 2024-10-12 10:56:16

一种基本方法是在服务器端或会话变量中记录最后一次单击发生的时间。每次点击时,检查上次点击时间。如果间隔太小,则返回而不开始其余过程。

另一种方法是在方法开始时将诸如“active”之类的布尔值设置为 true,并在方法结束时设置回 false。在方法开始时,检查该变量的当前状态并采取相应的操作。

这两种方法之间的主要区别在于,第一种方法允许该方法的多个实例同时运行,只要它们交错足够长的间隔即可。第二种方法将始终杀死或阻止该方法的任何新实例,直到当前实例结束。

One basic method is to record the time when the last click occurred in a server-side or session variable. On each click, check against the last click time. If the interval is too small, return without starting the rest of the process.

Another method is to set a boolean such as 'active' to true at the start of the method and back to false at the end. At the start of the method, check the current state of that variable and act accordingly.

The primary difference between these two methods is that the first will allow multiple instances of the method to be running at the same time so long as they are staggered by a long enough interval. The second method will always kill or block any new instances of the method until the current one ends.

从来不烧饼 2024-10-12 10:56:16

我会在其上放置一个 enabled=false ,直到部分回发完成,然后删除 enabled=false 属性。

Page_Load 上尝试类似的操作,这样它就会在第一次被禁用。

button.Attributes.Add("onclick",
                "this.disabled = true;"
                + this.ClientScript.GetPostBackEventReference(button, String.Empty) + ";");

然后在部分回发结束时重新启用它?

I would drop an enabled=false on it until the partial postback finishes and then remove the enabled=false attribute.

Try something like this on Page_Load so it will be disabled the first time.

button.Attributes.Add("onclick",
                "this.disabled = true;"
                + this.ClientScript.GetPostBackEventReference(button, String.Empty) + ";");

then re-enable it at the end of the partial postback?

或十年 2024-10-12 10:56:16

上述解决方案都不适合我。

我所做的是:

function InitializeRequest(sender, args) {
            var oSender = args._postBackElement;
            if (oSender.id == "btnSave") {
                oSender.href = "javascript: void(0);";
            }
        }

function EndRequestHandler(sender, args) {
            var oSender = sender._postBackSettings.sourceElement;
            if (oSender.id == "btnSave") {
                oSender.href = "__doPostBack('" + oSender.id + "', '');";
            }
        }

function load() {
            Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        }

        <body onload="load()">

None of the above solutions worked for me.

What I've done is:

function InitializeRequest(sender, args) {
            var oSender = args._postBackElement;
            if (oSender.id == "btnSave") {
                oSender.href = "javascript: void(0);";
            }
        }

function EndRequestHandler(sender, args) {
            var oSender = sender._postBackSettings.sourceElement;
            if (oSender.id == "btnSave") {
                oSender.href = "__doPostBack('" + oSender.id + "', '');";
            }
        }

function load() {
            Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        }

        <body onload="load()">
游魂 2024-10-12 10:56:16

将以下脚本放在页面的 ScriptManager 后面。

<script type="text/javascript"> 
var postbackControl = null; 
var parm = Sys.WebForms.PageRequestManager.getInstance(); 
parm.add_beginRequest(BeginRequestHandler); 
parm.add_endRequest(EndRequestHandler); 

function BeginRequestHandler(sender, args) 
{ 
postbackControl = args.get_postBackElement(); 
postbackControl.disabled = true; 
} 
function EndRequestHandler(sender, args) 
{ 
postbackControl.disabled = false; 
postbackControl = null; 
} 
</script>

Put the following script on the page after the ScriptManager.

<script type="text/javascript"> 
var postbackControl = null; 
var parm = Sys.WebForms.PageRequestManager.getInstance(); 
parm.add_beginRequest(BeginRequestHandler); 
parm.add_endRequest(EndRequestHandler); 

function BeginRequestHandler(sender, args) 
{ 
postbackControl = args.get_postBackElement(); 
postbackControl.disabled = true; 
} 
function EndRequestHandler(sender, args) 
{ 
postbackControl.disabled = false; 
postbackControl = null; 
} 
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文