Refresh Control without Updater Panel using ASP.NET AJAX

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

Answers


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.


Need Your Help

Refactoring an algorithm

c++ model-view-controller url-routing asp.net-mvc-routing

I'm trying to re-implement ASP.NET MVC routing rules in C++ for my own MVC application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.