队列 asp.net UpdatePanel 回发

发布于 2024-07-27 19:12:23 字数 248 浏览 1 评论 0原文

有没有办法使用 UpdatePanel 对回发进行排队?

我有一个带有许多文本框的表单。 每个文本框都包含在它自己的 UpdatePanel 中,并将 AutoPostBack 设置为 true。 因此,当文本框更改时,会发生回发。

viewstate 被禁用(所以不需要担心它)。

当用户更改一个文本框,然后快速切换到下一个文本框,更改它,然后再次切换时,就会出现此问题。 有些回发会丢失,我想避免这种情况。

is there a way to queue postbacks with UpdatePanel?

I have a form with many textboxes. each textbox is wrapped inside it's own UpdatePanel with AutoPostBack set to true. so, when textbox changes, postback occurs.

viewstate is disabled (so do not need to worry about it).

the problem appears when user changes one text box and then quickly tabs to the next text box, changes it, and tabs again. some of the postbacks are getting lost and I want to avoid that.

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

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

发布评论

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

评论(3

忆依然 2024-08-03 19:12:23

当更新面板即将触发时,您可以获得客户端“挂钩”。 这意味着您至少可以在更新面板刷新时暂时禁用文本框(或有某种“请等待”通知)。

以下 ASP.NET/Javascript 片段显示了如何拦截更新面板触发并禁用文本框。

<form id="form1" runat="server">
    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <div>
        <asp:UpdatePanel runat="server" ID="updatePane1">
            <ContentTemplate>
                <asp:TextBox runat="server" ID="textBox1" AutoPostBack="true" OnTextChanged="textBox_TextChanged" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <asp:UpdatePanel runat="server" ID="updatePane2">
            <ContentTemplate>
                <asp:TextBox runat="server" ID="textBox2" AutoPostBack="true" OnTextChanged="textBox_TextChanged" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
    </div>
    </form>
    <script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);
        function InitializeRequest(sender, args) {
            if (args._postBackElement.id == 'textBox1' || args._postBackElement.id == 'textBox2') {
                document.getElementById('textBox1').disabled = true;
                document.getElementById('textBox2').disabled = true; 
            }
        }
    </script>

我知道这并不完全是您最初要求的(“有没有一种方法可以使用 UpdatePanel 对回发进行排队”),但最终效果是它强制用户对他们的请求进行排队,因此在处理时不会超过一个一次。 您也可以将其修改为更优雅的东西。

You can get a client-side "hook" when the update panel is about to fire. This means that you could, at least, temporarily disable the text boxes (or have some sort of 'please wait' notification) while the update panel is refreshing.

The following snippet of ASP.NET/Javascript shows how to intercept the update panels firing and disable the textboxes.

<form id="form1" runat="server">
    <asp:ScriptManager runat="server"></asp:ScriptManager>
    <div>
        <asp:UpdatePanel runat="server" ID="updatePane1">
            <ContentTemplate>
                <asp:TextBox runat="server" ID="textBox1" AutoPostBack="true" OnTextChanged="textBox_TextChanged" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <asp:UpdatePanel runat="server" ID="updatePane2">
            <ContentTemplate>
                <asp:TextBox runat="server" ID="textBox2" AutoPostBack="true" OnTextChanged="textBox_TextChanged" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
    </div>
    </form>
    <script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);
        function InitializeRequest(sender, args) {
            if (args._postBackElement.id == 'textBox1' || args._postBackElement.id == 'textBox2') {
                document.getElementById('textBox1').disabled = true;
                document.getElementById('textBox2').disabled = true; 
            }
        }
    </script>

I know this isn't exactly what you originally asked for ("is there a way to queue postbacks with UpdatePanel"), but the net effect is that it forces the user to queue up their requests so no more than one is being processed at a time. You can probably amend this to something more elegant too.

素年丶 2024-08-03 19:12:23

没有内置的方法来控制它。 jQuery 有一些非常漂亮的东西,使 AJAX 调用变得非常简单。 您可以尝试以这种方式处理您自己的回发。

There's no built in way to control this. jQuery has some pretty nifty stuff that makes AJAX calls pretty simple. You might try looking into handling your own postbacks that way.

太傻旳人生 2024-08-03 19:12:23

我知道,这不是你问题的答案。 但如果您确实需要用更新面板包装每个文本框,我建议您重新考虑。 更新面板很有用,但使用时需要小心。 简单的 jQuery Ajax 解决方案可能更适合您的场景。

I know, this is not a answer to your question. But I would recommend a re-think, if you really need to wrap each text box with an update panel. Update panels are useful but you need to be careful in their usage. An plain jQuery Ajax solution may be better in your scenario.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文