views:

594

answers:

3

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.

A: 

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.

Spencer Ruport
+2  A: 

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.

Rob Levine
A: 

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.

ravi
this is what I ended up doing. update panel is ok for bulk operations (like show large portion of html or submit big form at a time). it sucks for small, quick postbacks to the server.
Ornus