Both export and attachment download from AJAX RadGrid

14 posts, 0 answers
  1. yerlan
    yerlan avatar
    18 posts
    Member since:
    Feb 2008

    Posted 26 Jul 2010 Link to this post

    Hello.

    I'm found in doc separate examples about exporting and downloading attachments from ajaxified RadGrid.

    After Implementing both of them = exporting doesn't work. Is it possible to combine this functions in one grid?

    Thanks.

  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 26 Jul 2010 Link to this post

    Hello Yerlan,

    Possible reason for this behavior is that your export button is ajaxified. Please examine the following link:
    Export from ajaxified grid

    If this is not the case, please provide a sample code so I can examine your approach.

    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. UI for ASP.NET Ajax is Ready for VS 2017
  4. yerlan
    yerlan avatar
    18 posts
    Member since:
    Feb 2008

    Posted 26 Jul 2010 Link to this post

    Daniel.

    Yes, my radGrid ajaxified, and i'm using solution from you provided link:

    1.function onRequestStart(sender, args) {
    2.    if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
    3.        args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
    4.        args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 ||
    5.        args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
    6.        args.set_enableAjax(false);
    7.    }
    8.}
    1.<telerik:RadAjaxManager ID="RadAjaxManager" runat="server">  
    2.    <ClientEvents OnRequestStart="onRequestStart"/>      
    3.</telerik:RadAjaxManager>
    (RadAjaxManager located on masterpage).

    Webpage contains RadGrid, ajaxified by RadAjaxManagerProxy.
    1.<telerik:RadGrid ID="MyGrid" runat="server">
    2.    <ClientSettings AllowColumnsReorder="true" ColumnsReorderMethod="Reorder">            
    3.        <Resizing AllowColumnResize="True" ResizeGridOnColumnResize="true"/>
    4.        <ClientEvents OnCommand="gridCommand"/>                 
    5.    </ClientSettings>       
    6.    ...
    7.</telerik:RadGrid>
    Grid's OnCommand event handled by this code on webpage:

    01.<telerik:RadCodeBlock runat="server">
    02.<script type="text/javascript">
    03.    <!--
    04.    function gridCommand(sender, args) {
    05.        var a = args.get_commandName();
    06.        if (args.get_commandName() == "DownloadAttachment") {
    07.            var manager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>');
    08.            manager.set_enableAJAX(false);
    09.  
    10.            setTimeout(function () {
    11.                manager.set_enableAJAX(true);
    12.            }, 0);
    13.        }
    14.    }
    15.    -->
    16.</script>
    17.</telerik:RadCodeBlock>
    =======================================================

    Problem in using this hacks in one grid. if enable grid's "onCommand" eventhandler - attachments works correct, but exporting freezes grid infinitly. if disable "onCommand" handler - export works correct, but attachments can't download from ajax-enabled grid.

  5. yerlan
    yerlan avatar
    18 posts
    Member since:
    Feb 2008

    Posted 27 Jul 2010 Link to this post

    Anyone have workaround?
  6. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 29 Jul 2010 Link to this post

    Hello Yerlan,

    I recommend that you try to use only the first approach. You just need to add the ID of the button that triggers the DownloadAttachment command.

    Sample code:
    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:Button ID="DownloadButton1" runat="server"
                 Text="Download"
                 CommandName="DownloadAttachment" />
        </ItemTemplate>
    </telerik:GridTemplateColumn>

    function onRequestStart(sender, args) {
        if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
            args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
            args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 ||
            args.get_eventTarget().indexOf("ExportToCsvButton") >= 0 ||
            args.get_eventTarget().indexOf("DownloadButton1") >= 0) {
            args.set_enableAjax(false);
        }
    }

    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. yerlan
    yerlan avatar
    18 posts
    Member since:
    Feb 2008

    Posted 29 Jul 2010 Link to this post

    Hello, Daniel.

    I'm removed GridAttchmentColumn and added GridTemplateColumn as in your code. Also I'm added ItemCommand event handler to RadGrid, but when i'm press to download button - event handler not executes (not only "DownloadAttachment" command, for all commands). What i'm doing wrong?

    01.<telerik:RadGrid ID="MyGrid" runat="server"
    02.    OnItemCommand="OnItemCommand">
    03.    <ClientSettings AllowColumnsReorder="true" ColumnsReorderMethod="Reorder">            
    04.        <Resizing AllowColumnResize="True" ResizeGridOnColumnResize="true"/>
    05.    </ClientSettings>       
    06.    ...         
    07.        <telerik:GridTemplateColumn UniqueName="MY_BLOB_COLUMN">
    08.            <ItemTemplate>
    09.            <asp:LinkButton ID="DownloadAttachmentButton" runat="server"
    10.                Text='<%# DataBinder.Eval(Container, "DataItem.MY_BLOB_COLUMN")%>' 
    11.                        CommandName="DownloadAttachment"/>
    12.            </ItemTemplate>
    13.            <EditItemTemplate>
    14.            <telerik:RadAsyncUpload runat="server" ID="AsuExamConclusionFile" 
    15.                           MaxFileSize="104857600"                  HttpHandlerUrl="~/CustomAsyncUploadHandler.ashx" MaxFileInputsCount="1" 
    16.                        OnClientDeleting="OnClientDeleting" OnClientFileUploaded="OnClientFileUploaded"/>
    17.                </EditItemTemplate>
    18.        </telerik:GridTemplateColumn>
    19.    ...
    20.</telerik:RadGrid>

    1.protected void OnItemCommand(object source, GridCommandEventArgs e)
    2.{
    3.    if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
    4.    {
    5.                  
    6.    }
    7.}

  8. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 04 Aug 2010 Link to this post

    Hello Yerlan,

    This approach works fine on my end. Please download the attached project (stripped for the sake of simplicity) and let me know if I'm missing something.

    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. Jeff
    Jeff avatar
    17 posts
    Member since:
    Apr 2008

    Posted 25 Aug 2010 Link to this post

    I tried the sample code, but there is no <ClientEvents /> element available on the RadAjaxManagerProxy.....
  10. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 31 Aug 2010 Link to this post

    Hello Jeff,

    You have to attach the event handler to the RadAjaxManager in the MasterPage. Of course, this means that the JS code should also be placed there.

    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
  11. Rajesh
    Rajesh avatar
    2 posts
    Member since:
    Aug 2010

    Posted 20 Sep 2010 Link to this post

    Hello Daniel...

    This Works Fine..

    Thanks
  12. Tony
    Tony avatar
    14 posts
    Member since:
    Sep 2010

    Posted 01 Mar 2011 Link to this post

    I have a situation that has the same issues as Yerlan found, but different circumstances. I am using a grid with the GridEditCommandColumn column and another column with a delete button. My grid is ajaxified via RadAjaxManager. I want to either hide the delete button column on edit, or trap deletions when editing (and cancel them) because you can be editing an item and delete another item, which can cause side-effects (if the item you delete is above the one you are editing, when the delete completes, you are not editing the item you were before the delete). So, I need to have a client-side handler for OnCommand. However, if I have such a handler, exporting no longer works. I cannot figure out why this is, but exporting is definitely broken if you define an OnCommand handler client-side. I have tried returning true, false and not returning anything from the OnCommand handler and it doesn't fix the export problem.

    So, the basic question is, how do I get a client-side OnCommand handler to not break the exporting capabilities? I am using the built-in buttons, and the infrastructure is correct in that, without the OnCommand handler, exporting works.
  13. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 07 Mar 2011 Link to this post

    Hello Tony,

    I strongly recommend that you avoid attaching the client-side OnCommand handler when binding RadGrid on the server since this will cause problems in some scenarios.
    This event is supported with client-side binding only.

    Best regards,
    Daniel
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  14. Tony
    Tony avatar
    14 posts
    Member since:
    Sep 2010

    Posted 09 Mar 2011 Link to this post

    Is there another method, then, for trapping the delete button click when a user is editing an item? Frankly, it seems like the grid control should be handling this - I would think that editing would need to be completed before you are allowed to do anything else, as though the editing operation is "modal" for the control. Is there some way I can handle this? I have thought of trapping it on the server side, but I am not going to know, on the server, if the user is in edit mode on the client, am I?
  15. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 15 Mar 2011 Link to this post

    Hello Tony,

    Generally speaking you have to use server-side approach in this case.
    The easiest way would be to handle the ItemCommand event and cancel the Delete command:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.DeleteCommandName && RadGrid1.EditIndexes.Count > 0)
        {
            e.Canceled = true;
            RadAjaxPanel1.Alert("Delete operation disabled when edit mode is active!");
        }
    }

    Of course it is also possible to hide the delete column if you prefer to do so.

    I hope this helps.

    Regards,
    Daniel
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017