Link to home
Start Free TrialLog in
Avatar of aloli
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 UpdatePanelAnimationExtender to disable all the buttons on the page and show a "Processing" message.  Once the button's onClick method is done, the UpdatePanelAnimationExtender'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 UpdatePanelAnimationExtender:

<cc1:UpdatePanelAnimationExtender ID="ae"
  runat="server" TargetControlID="upnlReportHolder">
     <Animations>
        <OnUpdating>
                  <Parallel >
                         <ScriptAction Script="onUpdating();" />
                        <EnableAction AnimationTarget="btnGenerateTestFile"  Enabled="false"/>
                        <EnableAction AnimationTarget="btnGenerateProdFile" Enabled="false" />
                        <EnableAction AnimationTarget="btnFTP" Enabled="false" />
                        
                        
            </Parallel>      
            </OnUpdating>
        <OnUpdated>
                  <Parallel>
                        <ScriptAction Script="onUpdated();" />
                        <EnableAction AnimationTarget="btnGenerateTestFile" Enabled="true" />
                        <EnableAction AnimationTarget="btnGenerateProdFile" Enabled="true" />
                        <EnableAction AnimationTarget="btnFTP" Enabled="true" />
                        
                        </Parallel>      
        </OnUpdated>
    </Animations>
</cc1:UpdatePanelAnimationExtender>

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_OnClick" OnClientClick="clearText()" CommandName="Stale" />
                              
And here is the OnClick method for the button:
protected void btnGenerateData_OnClick(Object 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.Standard && cbStandard.Checked)
                              || (fileType == BBP.PaymentFileType.TwentyFourHour && cb24hr.Checked)
                              || (fileType == BBP.PaymentFileType.PS2 && cbPS2.Checked)
                              || (fileType == BBP.PaymentFileType.RCT && cbRCT.Checked)
                              || (fileType == BBP.PaymentFileType.Type3000 && 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.AppSettings[storedProcAppSetting];
                              
                              //run service that gets accounts and generates files. returns a status message
                              string statusMessage = PaymentFileGeneratorService.GeneratePaymentFile(fileType, 12, runOnProduction, Convert.ToDateTime(txtStartDate.Text), Convert.ToDateTime(txtEndDate.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("Finished looping through file types.");
                  
            }
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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.
Avatar of aloli
aloli

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 UpdatePanelAnimationExtender 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?  
What version fo the AJAX control toolkit are you using?  I am running on 2008 with the source downloaded for build 62110.
Avatar of aloli

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?
Avatar of aloli

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="lblStandardStatusMessage" 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_OnClick" OnClientClick="clearText()" CommandName="Stale" />
                              </div>      
                              //...more buttons for other reports, removed for brevity
                              
                        </ContentTemplate>
                  </asp:UpdatePanel>
I see that UpdatePanel.UpdateMode="Conditional", 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:


<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>

Open in new window

Avatar of aloli

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.

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...
Avatar of aloli

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("Finished 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?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial