Updating a control without an update bar using ASP.NET AJAX
This question is directly related to my previous ASP.NET AJAX question
Is it possible to 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 put all the controls in the refresh panel after the first post went back to the process, which takes a few seconds to complete, any changes I made to the other contols showing up 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();
source to share
Place an update bar around the control you want to update, and create controls that fire change triggers on that update bar:
<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 ends, only the material inside the update panel changes. AJAX returns the values ββof all controls on the page, not just those contained in the content template.
Option 2 (and more involved) is to write a web service that does the calculation and some javascript to call it.
source to share