aloli
asked on
Problem with ASP.NET Ajax UpdatePanelAnimationExtender
I have have a button in an UpdatePanel that loops through a set of checkboxes and runs a service for each checked box. The service can take a few minutes so I use the UpdatePanelAnimationExtend er to disable all the buttons on the page and show a "Processing" message. Once the button's onClick method is done, the UpdatePanelAnimationExtend er's OnUpdated property then hides the "Processing" message and enables the buttons.
It works fine sometimes, but when more than 3 of the 6 boxes are checked, it sometimes hangs and never runs the OnUpated commands, just leaving the buttons disabled and the "Processing" message up. Though, through logging, I know the code itself isn't hanging, it's always getting to the end of the button's OnClick method.
How can I make sure the OnUpdated commands always run?
Here is the UpdatePanelAnimationExtend er:
<cc1:UpdatePanelAnimationE xtender ID="ae"
runat="server" TargetControlID="upnlRepor tHolder">
<Animations>
<OnUpdating>
<Parallel >
<ScriptAction Script="onUpdating();" />
<EnableAction AnimationTarget="btnGenera teTestFile " Enabled="false"/>
<EnableAction AnimationTarget="btnGenera teProdFile " Enabled="false" />
<EnableAction AnimationTarget="btnFTP" Enabled="false" />
</Parallel>
</OnUpdating>
<OnUpdated>
<Parallel>
<ScriptAction Script="onUpdated();" />
<EnableAction AnimationTarget="btnGenera teTestFile " Enabled="true" />
<EnableAction AnimationTarget="btnGenera teProdFile " Enabled="true" />
<EnableAction AnimationTarget="btnFTP" Enabled="true" />
</Parallel>
</OnUpdated>
</Animations>
</cc1:UpdatePanelAnimation Extender>
Here is the button (clearText is a simple javascript function that clears out the textbox contents):
<asp:Button ID="btnGenerateTestFile" runat="server" Text=" Get Count " OnClick="btnGenerateData_O nClick" OnClientClick="clearText() " CommandName="Stale" />
And here is the OnClick method for the button:
protected void btnGenerateData_OnClick(Ob ject sender, EventArgs e)
{
ResetLables();
Button btn = (Button) sender;
bool runOnProduction = btn.CommandName == "Production";
//Loop through all possible filetypes and generate XML files for ones that are checked off
foreach (BBP.PaymentFileType fileType in Enum.GetValues(typeof (BBP.PaymentFileType)))
{
if (
(fileType == BBP.PaymentFileType.Standa rd && cbStandard.Checked)
|| (fileType == BBP.PaymentFileType.Twenty FourHour && cb24hr.Checked)
|| (fileType == BBP.PaymentFileType.PS2 && cbPS2.Checked)
|| (fileType == BBP.PaymentFileType.RCT && cbRCT.Checked)
|| (fileType == BBP.PaymentFileType.Type30 00 && cbType3000.Checked)
|| (fileType == BBP.PaymentFileType.Wii && cbWii.Checked)
)
{
//set storedproc name based on file type
string storedProcAppSetting = _runOnProduction ? "StoredProc" + fileType : "StoredProc" + fileType + "Count";
string storedProc = ConfigurationManager.AppSe ttings[sto redProcApp Setting];
//run service that gets accounts and generates files. returns a status message
string statusMessage = PaymentFileGeneratorServic e.Generate PaymentFil e(fileType , 12, runOnProduction, Convert.ToDateTime(txtStar tDate.Text ), Convert.ToDateTime(txtEndD ate.Text), storedProc);
//set status message for the filetype's label
SetStatusMessage(fileType, statusMessage);
}
}
//I ALWAYS GET HERE EVEN WHEN THE ONUPDATED COMMANDS DON'T RUN
AppHelper.LogGeneral("Fini shed looping through file types.");
}
It works fine sometimes, but when more than 3 of the 6 boxes are checked, it sometimes hangs and never runs the OnUpated commands, just leaving the buttons disabled and the "Processing" message up. Though, through logging, I know the code itself isn't hanging, it's always getting to the end of the button's OnClick method.
How can I make sure the OnUpdated commands always run?
Here is the UpdatePanelAnimationExtend
<cc1:UpdatePanelAnimationE
runat="server" TargetControlID="upnlRepor
<Animations>
<OnUpdating>
<Parallel >
<ScriptAction Script="onUpdating();" />
<EnableAction AnimationTarget="btnGenera
<EnableAction AnimationTarget="btnGenera
<EnableAction AnimationTarget="btnFTP" Enabled="false" />
</Parallel>
</OnUpdating>
<OnUpdated>
<Parallel>
<ScriptAction Script="onUpdated();" />
<EnableAction AnimationTarget="btnGenera
<EnableAction AnimationTarget="btnGenera
<EnableAction AnimationTarget="btnFTP" Enabled="true" />
</Parallel>
</OnUpdated>
</Animations>
</cc1:UpdatePanelAnimation
Here is the button (clearText is a simple javascript function that clears out the textbox contents):
<asp:Button ID="btnGenerateTestFile" runat="server" Text=" Get Count " OnClick="btnGenerateData_O
And here is the OnClick method for the button:
protected void btnGenerateData_OnClick(Ob
{
ResetLables();
Button btn = (Button) sender;
bool runOnProduction = btn.CommandName == "Production";
//Loop through all possible filetypes and generate XML files for ones that are checked off
foreach (BBP.PaymentFileType fileType in Enum.GetValues(typeof (BBP.PaymentFileType)))
{
if (
(fileType == BBP.PaymentFileType.Standa
|| (fileType == BBP.PaymentFileType.Twenty
|| (fileType == BBP.PaymentFileType.PS2 && cbPS2.Checked)
|| (fileType == BBP.PaymentFileType.RCT && cbRCT.Checked)
|| (fileType == BBP.PaymentFileType.Type30
|| (fileType == BBP.PaymentFileType.Wii && cbWii.Checked)
)
{
//set storedproc name based on file type
string storedProcAppSetting = _runOnProduction ? "StoredProc" + fileType : "StoredProc" + fileType + "Count";
string storedProc = ConfigurationManager.AppSe
//run service that gets accounts and generates files. returns a status message
string statusMessage = PaymentFileGeneratorServic
//set status message for the filetype's label
SetStatusMessage(fileType,
}
}
//I ALWAYS GET HERE EVEN WHEN THE ONUPDATED COMMANDS DON'T RUN
AppHelper.LogGeneral("Fini
}
While I don't have a specific answer to this question, I do have some thoughts. It sounds like another possibility might be to timeout the "hung" operation, so that the OnUpdate would always fire.
ASKER
Thanks for the thought, but not sure I follow. The operation doesn't actually hang -- everything in the OnClick method finishes (which I can verify with the logging) but, for some reason, it just doesn't communicate that back to the UpdatePanelAnimationExtend er so OnUpdate doesn't fire.
It seems to only happen when the OnClick method is taking a longer time (say, over 2 minutes).
Any other thoughts?
It seems to only happen when the OnClick method is taking a longer time (say, over 2 minutes).
Any other thoughts?
What version fo the AJAX control toolkit are you using? I am running on 2008 with the source downloaded for build 62110.
ASKER
I think I'm running 2008. It's Version 3.0.20820.16598
I don't see the HTML for the UpdatePanel. Are you using async post back triggers?
ASKER
Ahh, maybe that is the problem. I'm not that experienced with update panels. Here is the HTML:
<asp:UpdatePanel runat="server" ID="upnlReportHolder" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" ID="pnlStatusMessages">
<div class="reportHolder">
<asp:CheckBox runat="server" ID="cbStandard" CssClass="checkbox" />
<asp:Label runat="server" ID="lblStandard" CssClass="reportName" Text="Standard Prepaid Payment File"></asp:Label>
<br /><asp:Label runat="server" ID="lblStandardStatusMessa ge" CssClass="statusMessage">< /asp:Label >
</div>
//...more reportHolder elements, removed for brevity
</asp:Panel>
<div class="btnHolder">
<asp:Button ID="btnGenerateTestFile" runat="server" Text=" Get Count " OnClick="btnGenerateData_O nClick" OnClientClick="clearText() " CommandName="Stale" />
</div>
//...more buttons for other reports, removed for brevity
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="upnlReportHolder" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" ID="pnlStatusMessages">
<div class="reportHolder">
<asp:CheckBox runat="server" ID="cbStandard" CssClass="checkbox" />
<asp:Label runat="server" ID="lblStandard" CssClass="reportName" Text="Standard Prepaid Payment File"></asp:Label>
<br /><asp:Label runat="server" ID="lblStandardStatusMessa
</div>
//...more reportHolder elements, removed for brevity
</asp:Panel>
<div class="btnHolder">
<asp:Button ID="btnGenerateTestFile" runat="server" Text=" Get Count " OnClick="btnGenerateData_O
</div>
//...more buttons for other reports, removed for brevity
</ContentTemplate>
</asp:UpdatePanel>
I see that UpdatePanel.UpdateMode="Co nditional" , so let's start there to try to find an answer.
Remember to set UpdatePanel's UpdateMode to Conditional
http://codeclimber.net.nz/archive/2007/05/24/updatemode-default-value-for-the-updatepanel-is-always.aspx
When you set the UpdateMode to Conditional, then the update will be initiated by a control inside of the UpdatePanel. Then, the UpdatePanel will asychronously update its contents. It looks like the "btnGenerateTestFile" button is the trigger for the operation, and it is inside the UpdatePanel's ContentTemplate, so it should post back the page, and cause the UpdatePanel to update.
ASP.NET AJAX Extensions Update Panel and Triggers
http://geekswithblogs.net/ranganh/archive/2007/05/16/112526.aspx
You can also define asychronous post back triggers for the UpdatePanel, that will cause the panel to update.
Example:
Remember to set UpdatePanel's UpdateMode to Conditional
http://codeclimber.net.nz/archive/2007/05/24/updatemode-default-value-for-the-updatepanel-is-always.aspx
When you set the UpdateMode to Conditional, then the update will be initiated by a control inside of the UpdatePanel. Then, the UpdatePanel will asychronously update its contents. It looks like the "btnGenerateTestFile" button is the trigger for the operation, and it is inside the UpdatePanel's ContentTemplate, so it should post back the page, and cause the UpdatePanel to update.
ASP.NET AJAX Extensions Update Panel and Triggers
http://geekswithblogs.net/ranganh/archive/2007/05/16/112526.aspx
You can also define asychronous post back triggers for the UpdatePanel, that will cause the panel to update.
Example:
<asp:UpdatePanel ID="UpdatePanel1" runat="Server" UpdateMode="conditional">
<ContentTemplate>
Label within the Update Panel Refreshed at:
<asp:Label ID="Label1" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<%--<asp:PostBackTrigger ControlID="Button1" />--%>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
ASKER
You're right, "btnGenerateTestFile" is the trigger. And I do have the update panel UpdateMOde set to Conditional, as I think it should be. Though I don't see how the AsyncPostBackTrigger helps me, since the trigger I'm using is already inside the UpdatePanel. And, more to the point, the whole Update Panel process is working as expected.
The real issue is that the OnUpdated property of the extender is not always firing and this seems to be related to how long the process started by the btnGenerateTestFile's OnClick method takes. When it's short, everything works as expected (the update panel updates, the OnUpdated actions fire), but when the process goes for longer than a couple minutes, OnUPdated never fires.
The real issue is that the OnUpdated property of the extender is not always firing and this seems to be related to how long the process started by the btnGenerateTestFile's OnClick method takes. When it's short, everything works as expected (the update panel updates, the OnUpdated actions fire), but when the process goes for longer than a couple minutes, OnUPdated never fires.
That was just a small reference to make sure that I had the right thinking, and to explain the reason for the previous question...
The AsyncPostBackTrigger is not going to help you, since you should be getting an Update from the button, just not all the time.
Does it matter which CheckBox controls are checked, or just how many? In other words, could you be having a problem with the btnGenerateData_OnClick method...
The AsyncPostBackTrigger is not going to help you, since you should be getting an Update from the button, just not all the time.
Does it matter which CheckBox controls are checked, or just how many? In other words, could you be having a problem with the btnGenerateData_OnClick method...
ASKER
Gotcha.
No, it doesn't seem to matter which ones are checked, it works with various combinations and always works if I go through and do one at a time. But when I have more than 2 or 3 selected at once, that's generally when I see the problem.
To be clear, though, even in those situations, the btnGenerateData_OnClick method finishes (I know because I always see the logging done by the last line in the method, "AppHelper.LogGeneral("Fin ished looping through file types.");" It's just that even though the method finished, OnUpdated never fires. It's almost like after a certain amount of time, the extender stops listening for a response or something. Possibly a bug with the extender?
No, it doesn't seem to matter which ones are checked, it works with various combinations and always works if I go through and do one at a time. But when I have more than 2 or 3 selected at once, that's generally when I see the problem.
To be clear, though, even in those situations, the btnGenerateData_OnClick method finishes (I know because I always see the logging done by the last line in the method, "AppHelper.LogGeneral("Fin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.