This is a migrated thread and some comments may be shown as answers.

Export grid to Excel - Master Page with RadAjaxManager, Content Page with RadAjaxManagerProxy

10 Answers 472 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 17 Jul 2008, 01:56 PM
Hi there,

Sorry, previously posted this to the wrong forum because the treeview that lists the forums truncates the top level name so you've got "RadControls for ASP.NE.." and "RadControls for ASP.NET"; I picked the wrong one. :(

Anyway...

I have a page with a grid and an 'export to Excel' button. Until recently the page was a standalone page with RadAjaxManager on it. Everything worked perfectly using the manager's OnRequestStart client-side event to set EnableAjax to false for the export button.

I've since converted the page to a Content page, removed the RadAjaxManager and placed it on the Master Page, and placed a RadAjaxManagerProxy on the Content page.

Now when I click the export button nothing happens.

I've kept the OnRequestStart code for the RadAjaxManager on the Master Page, but it's not getting called. I suspect I need to do something with the proxy on the Content page when the export button is clicked, but I can't find any information about this in any postings on this forum.

Can you point me in the right direction?

Many thanks in advance,
Rob

10 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 18 Jul 2008, 01:08 PM
Hi Rob,

Please try getting your RadAjaxManager in the javascript inside the content page where the button is placed. You can do it in the following way:

$find("<%= RadAjaxManager.GetCurrent(Page).ClientID%>").enableAjax = false;

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
HHalim
Top achievements
Rank 2
answered on 18 Jul 2008, 06:10 PM
Similar issue here.
I have Export to Excel link button inside the <CommandItemTemplate>, such as this:
<CommandItemTemplate> 
    <asp:LinkButton ID="lnkXExcel" runat="server" OnClick="lnkXExcel_Click"><img id="Img6" class="GridTopButton" alt="" src="~/images/sm_excel.gif" runat="server" />&nbsp;Export to Excel</asp:LinkButton> 
</CommandItemTemplate> 
 

I put the OnRequestStart on the master page, and tried to retrieve the <%= lnkXExcel .ClientID %> , but got an error.

So, I tried the RadAjaxManager enableAjax = false; with the link button OnClientClick="DisableAjax()", but this does not work either.

Of course the easiest solution is to put the Export to Excel button outside the ajaxified radgrid, but it does not look as integrated.

0
Gian Carlo Zamboni
Top achievements
Rank 1
answered on 18 Jul 2008, 06:44 PM
I made this to make the export work with a master page, content and webusercontrol.

Use this at OnInit or PageLoad event.

    RadAjaxManager oAjaxMan = (RadAjaxManager)this.Page.Master.FindControl("RadAjaxManager1"); 
    oAjaxMan.ClientEvents.OnRequestStart = "mngRequestStarted"
 
    StringBuilder ostrScript = new StringBuilder(); 
    ostrScript.Append("function mngRequestStarted(ajaxManager, eventArgs)"); 
    ostrScript.Append("{"); 
    ostrScript.Append(" if(eventArgs.EventTarget == \"" + this.ibtExportXLS.UniqueID + "\" || eventArgs.EventTarget == \"" + this.ibtExportPDF.UniqueID + "\" || eventArgs.EventTarget == \"" + this.ibtExportCSV.UniqueID + "\")"); 
    ostrScript.Append(" {"); 
    ostrScript.Append("   eventArgs.EnableAjax = false;"); 
    ostrScript.Append(" }"); 
    ostrScript.Append("}"); 
    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "mngRequestStarted", ostrScript.ToString(), true); 
Hope this helps.


0
HHalim
Top achievements
Rank 2
answered on 19 Jul 2008, 08:45 PM
Excellent post by Gian!

So, here's what I had to do:
I put Gian's code inside a general utility class:
        public static void RegisterExport(Page page, string excelUID) 
        { 
            Telerik.Web.UI.RadAjaxManager oAjaxMan = (Telerik.Web.UI.RadAjaxManager)page.Master.FindControl("RAM"); 
            oAjaxMan.ClientEvents.OnRequestStart = "mngRequestStarted"
 
            StringBuilder ostrScript = new StringBuilder(); 
            ostrScript.Append("function mngRequestStarted(ajaxManager, eventArgs)"); 
            ostrScript.Append("{"); 
            ostrScript.Append(" if(eventArgs.EventTarget == \"" + excelUID + "\")"); 
            ostrScript.Append(" {"); 
            ostrScript.Append("   eventArgs.EnableAjax = false;"); 
            ostrScript.Append(" }"); 
            ostrScript.Append("}"); 
 
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "mngRequestStarted", ostrScript.ToString(), true); 
        } 
 

And I used radgrid's ItemCreated event to get to the link buttons:
        protected void RGrid_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridCommandItem) 
            { 
                GridCommandItem commandItem = e.Item as GridCommandItem; 
                LinkButton button = commandItem.FindControl("lnkXExcel"as LinkButton; 
 
                Util.RegisterExport(this.Page, button.UniqueID); 
            } 
        } 
 

Works great. Thank you Gian Carlo Zamboni!
0
Rob
Top achievements
Rank 1
answered on 28 Jul 2008, 11:28 AM
I just cannot get this to work.

I would be really grateful if someone at Telerik could post a really simple sample application that shows...

- A master page with RadAjaxManager and Loading Panel

- A content page with RadAjaxManagerProxy, ASP.Net button, and RadGrid. Grid should be populated with data upon press of button, loading panel should show while loading grid, and everything done without postback.

If you already have a sample like this available then apologies if I've missed it, but I'm sure this example will help anyone else that may struggle with the same thing.

Many thanks in advance,
Rob
0
Veli
Telerik team
answered on 28 Jul 2008, 01:22 PM
Hi Rob,

Please find attached a sample project demonstrating the setup of RadAjaxManager in a master page and RadGrid in a content page. Prior to rendering RadGrid, a client script is registered to the OnRequestStart client event of RadAjaxManager, which handles the disabling of AJAX when the export button is clicked.

You can check out the RadAjaxManagerProxy registration and the client event registration in RadGrid's PreRender handler on the server.

The sample has been created using RadControls for ASP.NET AJAX 2008.1 619, so all you need to do is add the libraries to the Bin folder.

Kind regards,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rob
Top achievements
Rank 1
answered on 28 Jul 2008, 03:08 PM
Thanks for your response - speedy as always.

Just one point about your example...

- In default.aspx.cs your RadGrid1_PreRender event makes a reference to RadAjaxManager:

RadAjaxManager.GetCurrent(Page).ClientEvents.OnRequestStart =   
"RequestStart"

This is incorrect as you need to reference the RadAjaxManager on the Master page - this I managed to do by creating a reference to it using Page.Master.FindControl. The Excel functionality works fine after doing this.

Thanks for your quick feedback though - it has helped me solve the problem I was having. I just have one more issue with my loading panel to resolve now, but I'll start a new thread for that.
0
Doug Beard
Top achievements
Rank 1
answered on 11 Apr 2012, 02:30 PM
The suggested solution is an Anti-Pattern, where-by the MasterPage must know too much about the ContentPage, namely the button Id.
Is there yet a more standardized approach to this problem?  In our case we have hundreds of contentpages, in which the Export likely exists.  Our Export buttons are not uniformly named as many may exist.  We would have to add hundreds of different EventArg cases to the MasterPage, which is undesirable.
0
Doug Beard
Top achievements
Rank 1
answered on 11 Apr 2012, 02:31 PM
Double Post Redacted
0
Karan
Top achievements
Rank 1
answered on 05 Feb 2014, 07:33 AM
hii

thanks for every one to discuss n giving your solution.!!

I am facing a problem in rad grid to export data in excel, when i am using in separate page of asp.net ,it's working fine when same code is in child page it's not working.so plz help me

Thanks 
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Veli
Telerik team
HHalim
Top achievements
Rank 2
Gian Carlo Zamboni
Top achievements
Rank 1
Rob
Top achievements
Rank 1
Doug Beard
Top achievements
Rank 1
Karan
Top achievements
Rank 1
Share this question
or