Search code examples
c#asp.netasp.net-ajaxazurereport-viewer2010

AjaxMethods in Windows Azure not working


We are showing reports in our Azure web application using ReportViewer (rdlc) control in VS2010 which is working perfectly. Recently my client asked me to capture the the Print event for ReportViewer and log an entry on the server. I've hooked the with the print button.. This works perfectly when I run the web application on a local environment. However, on Azure, the Ajax method never gets called from client side. Please suggest what to do? Is there a limitation for Ajax in Azure Environment?

I'm registering the Page on Page_Load in code behind

protected void Page_Load(object sender, EventArgs e)
{
  Ajax.Utility.RegisterTypeForAjax(typeof(Pages.Report));

  ImageButton btnPrint = new ImageButton();
  btnPrint = ((ImageButton)(this.FindControl("ctl00$" + ReportViewer1.ClientID.Replace("_","$") + "$ctl06$ctl06$ctl00$ctl00$ctl00")));
  btnPrint.Attributes["onclick"] += "attachEventForPrint();";
}

 [AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]

 public static void LogEvent(int pLoggingEvent)
 {
  // Addded logic to log event
 }

And in ASPX file following function was added in JS

 function attachEventForPrint() {
   if (typeof (Report) != "undefined") {
                Report.LogEvent(4);
            }
        }

Solution

  • The good news is that I don't think there's any limitation with using ajax controls - I've used a few and they just worked.

    Some things to check might be:

    • can you use Fiddler to view the HTTP trace - is a request being sent to the server when you click on the the print button?
    • can you use a javascript debugger to check that there are no errors being reported when attachEventForPrint occurs?
    • are there any issues here with "State" - especially with Session storage?

    One other thing to check is whether there is a more maintainable way to access the print button - the "$ctl06$ctl06$ctl00$ctl00$ctl00" just looks like it is asking for trouble either now or at some point in the future