tags:

views:

1570

answers:

1

This question is directly related to my previous question ASP.NET AJAX

Is it possible to perform the post back asynchronously? I have multiple CustomTextbox controls on the page, when i post back i want to update another control on the form.

If i place all the controls in an updater panel after the first post back to a process that takes a couple of seconds to complete, any changes i have made to other contols rendered with their original values.

Any idea how to fix this?

Type.registerNamespace('Demo');

Demo.CustomTextBox = function(element) {
    Demo.CustomTextBox.initializeBase(this, [element]);
}

Demo.CustomTextBox.prototype = {

    initialize: function() {
        Demo.CustomTextBox.callBaseMethod(this, 'initialize');

        this._onblurHandler = Function.createDelegate(this, this._onBlur);

        $addHandlers(this.get_element(),
                     {
                         'blur': this._onBlur
                     },
                     this);
    },

    dispose: function() {
        $clearHandlers(this.get_element());

        Demo.CustomTextBox.callBaseMethod(this, 'dispose');
    },

    _onBlur: function(e) {
    if (this.get_element() && !this.get_element().disabled) {
            /* Cridit to AdamB for this line of code */
            __doPostBack(this.get_element().id, 0);
        }
    }
}

Demo.CustomTextBox.registerClass('Demo.CustomTextBox', Sys.UI.Control);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
+2  A: 

Only put the update panel around the control that needs to be updated, and make the controls that trigger the changes triggers on that update panel:

<asp:TextBox runat="server" ID="Entry2" />
<asp:TextBox runat="server" ID="Entry1" />
<asp:UpdatePanel>
    <ContentTemplate>
        <asp:TextBox runat="server" ID="Result" ReadOnly="true" />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Entry1" />
        <asp:AsyncPostBackTrigger ControlID="Entry2" />
    </Triggers>
</asp:UpdatePanel>

As a result, when the postback finishes, only the stuff inside the update panel changes. AJAX posts back the values of all the controls on the page, not just the ones in the content template.

Option 2 (and more involved) would be to write a web service that does the calculation and some javascript to call it.

Robert Wagner
Cheers Robert, i thought this might be the case.
Rohan West