RadGrid Export to Excel with RadAjaxPanel

11 posts, 0 answers
  1. Dave Miller
    Dave Miller avatar
    6 posts
    Member since:
    Oct 2009

    Posted 25 Feb 2010 Link to this post

    I have a project that is coming to its conclusion of the next day or so.  The last component of the project benefited greatly by implementing Telerik's Ajax.  I wrapped my project in a RadAjaxPanel and all worked incredibly well.... except my export to excel class.  I reworked all with RadGrid in hopes that it would work seamlessly.  It looks great but I get no response from the button that executes the RadGrid export to excel function.  The app hesitates briefly and than returns control to the user.  I tried just using the RadAjaxManager and the wheels fell off of my MultiView views.  I have very limited exposure to Telerik and have spent the last two days searching for specific code on how to handle this.  Could you please point me to code that would show this in action?  I am coding in VB (VS2005).  Another simpler question is how do I left justify the RadGrid.MasterTableView Caption?
    Thanks very much
  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 25 Feb 2010 Link to this post

    Hello Dave,

    The first problem can be easily solved with a few lines of JavaScript:
    <script type="text/javascript">
        function requestStart(sender, args)
        {
            if (args.get_eventTarget().indexOf("btnExport") >= 0)
                args.set_enableAjax(false);
        }
    </script>
     
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="requestStart">
        <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
        <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
            <%--...--%>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>

    You can set the desired alignment to the caption using its CSS class:
    <style type="text/css">
        .rgCaption
        {
            text-align: left;
        }
    </style>

    Note that the exported file won't be affected until you inject the CSS code in the output:
    protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
    {
        string myClass = ".rgCaption { text-align: left; }";
        string cssStyle = String.Format("<style type='text/css'>{0}</style>", myClass);
        e.ExportOutput = e.ExportOutput.Replace("<head>", "<head>" + cssStyle);
    }

    Protected Sub RadGrid1_GridExporting(source As Object, e As GridExportingArgs) Handles RadGrid1.GridExporting
        Dim myClass As String = ".rgCaption { text-align: left; }"
        Dim cssStyle As String = String.Format("<style type='text/css'>{0}</style>", myClass)
        e.ExportOutput = e.ExportOutput.Replace("<head>", "<head>" + cssStyle)
    End Sub

    Regards,
    Daniel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Dave Miller
    Dave Miller avatar
    6 posts
    Member since:
    Oct 2009

    Posted 26 Feb 2010 Link to this post

    Daniel, Thank you for the very prompt response.  This did in fact resolve the problems that I knew I had. Now, during testing, I have found a few problems that I didn't know I had.  I have set paging to 50 per page. Requests for the next page result in no data returned.  Also "IgnorePaging='true'" results in "Object reference not set to an instance of an object. " on export.  I have worked around this by just eliminating paging and displaying all results to the grid.  The problem that I have not be able to work around yet is the fact that larger requests that may take 1 to 5 minutes (5000 to 10000 rows) result in either a hung browser or "Sys.WebForms.PageRequestManagerTimoutException: The server request timed out." while attempting to populate the grid.  These pages returned with no issues pre Ajax.  Any help on this would be greatly appreciated.  I may need to back out all Ajax functionality for my release next week but I would like to work this out and perhaps apply a post release fix.
    Thanks again,
    Dave
  4. Dave Miller
    Dave Miller avatar
    6 posts
    Member since:
    Oct 2009

    Posted 26 Feb 2010 Link to this post

    Daniel,  I may have resolved part of my more pressing problem regarding the timeout. Unfortunately in my searching I only used "PageRequestManagerTimoutException" which didn't yield any helpful results.  Shortly after my last post I searched on the full error "Sys.WebForms.PageRequestManagerTimoutException: The server request timed out."  and found the AsyncPostBackTimeout parameter. I no longer get the timeout error.  Now after several minutes the grid begins to display but than results in a javascript error referring to not enough space.  If I could address my paging issue this may go away but is there something else I need to do to address SQL queries that are slow to response and return over 5000 rows?
    Thanks
  5. Dave Miller
    Dave Miller avatar
    6 posts
    Member since:
    Oct 2009

    Posted 26 Feb 2010 Link to this post

    Daniel,  I may have resolved part of my more pressing problem regarding the timeout. Unfortunately in my searching I only used "PageRequestManagerTimoutException" which didn't yield any helpful results.  Shortly after my last post I searched on the full error "Sys.WebForms.PageRequestManagerTimoutException: The server request timed out."  and found the AsyncPostBackTimeout parameter. I no longer get the timeout error.  Now after several minutes the grid begins to display but than results in a javascript error referring to not enough space.  If I could address my paging issue this may go away but is there something else I need to do to address SQL queries that are slow to response and return over 5000 rows?
    Thanks
  6. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 26 Feb 2010 Link to this post

    Hello Dave,

    Judging by your explanation, this is databinding-related problem. You could sidestep the issue if you use advanced data-binding with NeedDataSource.
    Advanced Data-binding help topic
    Advanced Data Binding demo

    Let me know whether this helps.

    Best regards,
    Daniel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Dave Miller
    Dave Miller avatar
    6 posts
    Member since:
    Oct 2009

    Posted 26 Feb 2010 Link to this post

    If tried to follow this code and have not had much luck.  I placed a break point in the 

    RadGrid1_NeedDataSource Sub.  I also placed the OnNeedDataSource="RadGrid1_NeedDataSource" in the radgrid paramters.  The sub does not seem to fire.  Is there any chance that I need to disable ajax on the next page button as I did earlier in the post for the export button?

  8. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 26 Feb 2010 Link to this post

    Hello Dave,

    This is unlikely to be related to AJAX - it seems like a databinding issue to me. May I ask you to attach a sample project to a formal support ticket so I can examine it on my end? This way I will be able to provide more to-the-point answer.

    Best regards,
    Daniel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Dave Miller
    Dave Miller avatar
    6 posts
    Member since:
    Oct 2009

    Posted 26 Feb 2010 Link to this post

    Daniel,
    I really appreciate your prompt assistance.  Given my current lack of knowledge of the Telerik suite and my required timeline I will need to change course a bit.  Fortunately a piece of information that you gave me early on will help me keep most of my application in tact.  I moved away from the GridView when I ran into problems with my export class.  This problem was the result of wrapping the MultiView in a RadAjaxPanel.  Your hint about using client side script to disable ajax on specific buttons has allowed me to revert to the GridView for now and leave all my other ajax aware controls in place.  I'm sure my next project will benefit from ajax and you will be hearing from me again.  Thank you.
    Dave
  10. nick chance
    nick chance avatar
    6 posts
    Member since:
    Oct 2012

    Posted 01 Nov 2012 Link to this post

    Many thanks Daniel for a perfect explanation. This worked for me (once I'd worked out the name of the Excel button was "ExportToExcelButton"). Very many thanks Daniel, much obliged - Nick C. 

     

  11. Perumal
    Perumal avatar
    1 posts
    Member since:
    Nov 2015

    Posted 04 Nov 2015 Link to this post

    Hi Team,

     Am getting the issue when I place my radgrid control inside the radajaxpanel. I have enabled the ShowExportToExcelButton="true" in the radgrid.so When I click export to excel getting the javascript error.pls find the below error

    " JavaScript runtime error: Unable to get property 'Cols' of undefined or null reference telerik export to excel "

    Any solution pls. its urgent.

     

Back to Top