Export-to-Excel button within the toolbar

9 posts, 1 answers
  1. Peter
    Peter avatar
    9 posts
    Member since:
    May 2009

    Posted 05 May 2009 Link to this post

    Hi

    I would like to place my Export-to-Excel button within the toolbar.

    This button should be defined as a synchronous postback trigger for my update panel.
    The button is placed within CommandItemTemplate tags.

    My problem is that the concept that has worked with other asp.net controls does not seem to work with RadGrid.

    <asp:PostBackTrigger ControlID="myRadGrid$btnExport" />
    In this type of declaration the error message I receive is the following:

    A control with ID 'myRadGrid$btnExport' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.


    Can you please give me some suggestion?
  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 06 May 2009 Link to this post

    Hello Peter-

    If you inspect the rendered Grid, you'll see that the btnExport ID is actually much more nested because it is rendered in a template container. That makes it difficult to target with this syntax.

     A better approach may be to simply use the RadGrid as your PostBackTrigger. Due to event bubbling, the command fired from the command item will cause the Grid to trigger your postback event. You can then handle the OnItemCommand grid event on the server and use a CommandName to detect when your export button has been clicked. Check out this page in the docs for more info on command bubbling:

    http://www.telerik.com/help/aspnet-ajax/grdcommandreference.html

    Hope this helps.

    -Todd
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Peter
    Peter avatar
    9 posts
    Member since:
    May 2009

    Posted 06 May 2009 Link to this post

    the btnExport ID is actually much more nested because it is rendered in a template container

    There is templating in a lot of ASP.NET controls (such as FormView, GridView, etc.) where the ParentControlID$ControlWithinTemplateID formula works properly for declarative targeting.

    This is why I am missing this.

    use the RadGrid as your PostBackTrigger

    I can't, because in this case I will lose the AJAX functionality provided by the grid.
  5. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 06 May 2009 Link to this post

    I see. It sounds like you're simply trying to enable "Export from an Ajaxified Grid."

    If that's the case, there are a few help topics prepared that can assist you with this task:

    DOCS: Export from Ajaxified Grid

    CODE: Export Grid Content to Excel with Ajax Enabled

    Take a look at the approaches outlined there and let me know if they help you solve your problem. I will also look deeper at the template control targeting syntax and try to figure out why it's not working as expected.

    -Todd
  6. Peter
    Peter avatar
    9 posts
    Member since:
    May 2009

    Posted 07 May 2009 Link to this post

    These documents describe that Excel exporting only works with synchronous postbacks.
    I understand this.

    My problem is only connected with the template control targeting syntax.

  7. Answer
    Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 07 May 2009 Link to this post

    Hello Peter-

    Sorry for the confusion. I was fairly certain you already understood the need for PostBacks based on your approach with the PostBackTrigger. What you should find, however, is that in the linked resources there is guidance showing you how to enable a button in a CommandItemTemplate to fire a PostBack event in a ajaxified RadGrid. Specifically, you can find the relevant code snippet here:


    Essentially, you handle the OnItemCreated event of the RadGrid and implement code like this:

    if (e.Item is GridCommandItem)   
    {   
                Button btncmd = (e.Item as GridCommandItem).FindControl("btnExcel"as Button;   
                ScriptManager1.RegisterPostBackControl(btncmd); 

    Hope that helps.

    -Todd
  8. Peter
    Peter avatar
    9 posts
    Member since:
    May 2009

    Posted 09 May 2009 Link to this post

    Thanks.

    Using this last approach it works now.
  9. Atul
    Atul avatar
    2 posts
    Member since:
    Jun 2010

    Posted 18 Jun 2010 Link to this post

    Hi,
    I am facing the same issue :(. I have already gone through the same link ans applied it However it gives me exception on the line mentioned below:

    ScriptManager1.RegisterPostBackControl(btncmd);

    It gives me exception as it is not able to recognize the control.  The error I get is that find no control.
    I have used Commanditemtemplate and Itemcreated events and followed the same procedure.My data grid lies in the asp: update panel..

    A help wd b greatful as I am stuck with this code for last 5 days .


    Thanks,
    Atul

  10. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 21 Jun 2010 Link to this post

    Hello Atul,

    Please make sure that the ID of your button matches the argument, passed to the FindControl method in the ItemCreated event handler.
    Button btncmd = (e.Item as GridCommandItem).FindControl("THE_ID_OF_YOUR_BUTTON") as Button;

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017