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();

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Cheers Robert, i thought this might be the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.