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

Export to pdf with DNN

3 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 20 Apr 2011, 03:19 PM
I've got a radgrid in a dnn module/user control and I want to add exporting to pdf. The module is ajax enable via dnn and I'm pretty sure my problem is related to not doing a full postback. Nothing happens when you click the export to pdf button. I'm trying to register the export to pdf button to postback on the page load with no luck. For some reason I can't find the control.

Any help is appreciated, thanks.
protected void Page_Load(System.Object sender, System.EventArgs e)
{
    RadGrid InventoryGrid = (RadGrid)InventoryRadGrid;
    Control pdfExportButton = (Control)InventoryRadGrid.MasterTableView.FindControl("ExportToPdfButton");
    if (pdfExportButton != null)
        ScriptManager.GetCurrent(Page).RegisterPostBackControl(pdfExportButton);
    else messageLabel.Text = "Export to PDF Control Not Found";
    if (!IsPostBack)
    {
    }
}

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Apr 2011, 05:33 PM
Hello Tim,

Due to the fact that the items in RadGrid are naming containers, you have to use the FindControl method on the item itself. Sample code:
GridItem gitem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
item.FindControl("...")....;

Alternative approach would be to use client-side code for canceling the async request:
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
function initializeRequestHandler(sender, args)
{
    if (args.get_postBackElement().id.indexOf("EXPORT_CONTROL_ID") != -1)
    {
        args.set_cancel(true);
        sender._form["__EVENTTARGET"].value = args.get_postBackElement().id.replace(/\_/g, "$");
        sender._form["__EVENTARGUMENT"].value = "";
        sender._form.submit();
        return;
    }
}

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Tim
Top achievements
Rank 1
answered on 17 May 2011, 04:27 PM
Thanks for information Daniel. I had to set this aside for a few weeks and I just got back to it. In case anyone else is trying to figure this out the FindControl approach doesn't work during page load on the server side.  I was getting an error message: "Index was outside the bounds of the array". I'm pretty sure the radGrid hasn't been created when the page load starts. 

The client-side code did work. Just changed  "EXPORT_CONTROL_ID" to the name of your control.

Thanks.
0
Daniel
Telerik team
answered on 20 May 2011, 02:40 PM
Hello Tim,

Thank you for sharing the solution with our community. Let me know if you need further assistance.

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Tim
Top achievements
Rank 1
Share this question
or