[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with ASP.NET Ajax UpdatePanelAnimationExtender

Posted on 2009-12-29
12
Medium Priority
?
2,235 Views
Last Modified: 2012-05-08
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.");
                  
            }
0
Comment
Question by:aloli
  • 6
  • 5
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26146523
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.
0
 

Author Comment

by:aloli
ID: 26146866
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?  
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26147120
What version fo the AJAX control toolkit are you using?  I am running on 2008 with the source downloaded for build 62110.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:aloli
ID: 26147174
I think I'm running 2008. It's Version 3.0.20820.16598
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26147799
I don't see the HTML for the UpdatePanel.  Are you using async post back triggers?
0
 

Author Comment

by:aloli
ID: 26147858
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>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26147984
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

0
 

Author Comment

by:aloli
ID: 26148087
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.

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 26148142
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...
0
 

Author Comment

by:aloli
ID: 26148196
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?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 26148355
Here is what I think might be the problem--these processes happen asynchronously.  This means that we can't guarantee the order of operations.  I know that sometimes a problem can be solved with the UpdatePanel by moving the trigger control outside of the panel, and specifying an AsynchPostBackTrigger to that control, but this feels more complicated than that...

I know that the UpdatePanelAnimationExtender is a pretty simple extender.  It is the binder between the UpdatePanel and the animation scripts.
[Designer("AjaxControlToolkit.UpdatePanelAnimationDesigner, AjaxControlToolkit")]
    [RequiredScript(typeof(CommonToolkitScripts), 0)]
    [RequiredScript(typeof(AnimationScripts), 1)]
    [RequiredScript(typeof(AnimationExtender), 2)]
    [ClientScriptResource("AjaxControlToolkit.Animation.UpdatePanelAnimationBehavior", "AjaxControlToolkit.UpdatePanelAnimation.UpdatePanelAnimationBehavior.js")]
    [TargetControlType(typeof(UpdatePanel))]
    [ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    [ToolboxBitmap(typeof(UpdatePanelAnimationExtender), "UpdatePanelAnimation.UpdatePanelAnimation.ico")]
    public class UpdatePanelAnimationExtender : AnimationExtenderControlBase

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question