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

Disable ajax for export when calling masterTable.exportToExcel();

1 Answer 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yuval
Top achievements
Rank 1
Yuval asked on 27 Feb 2012, 02:36 PM
Hi,

I am tring to create a button outside the RadGrid that will export the grid data.

I am using RadAjaxManagerProxy and added
protected void Page_Load(object sender, EventArgs e)
       {
           RadAjaxManager.GetCurrent(this.Page).ClientEvents.OnRequestStart = "onRequestStart";
           if (!IsPostBack) this.DataBind();
       }
on the client side I've
<telerik:RadButton runat="server" ID="export" OnClientClicked="ExportGrid" />
and the following script code in the head section
<script type="text/javascript">
 
    function ExportGrid(sender, args) {
        var masterTable = $find("<%=RadGrid1.ClientID %>").get_masterTableView();
        masterTable.exportToExcel();
 
    }
    function onRequestStart(sender, args) {
        alert(args.get_eventTarget());
        if (args.get_eventTarget().indexOf("btnExport") >= 0)
            args.set_enableAjax(false);
    }
</script>

The problem is that inlike export from the grid button , this way args.get_eventTarget() is always "ctl00$ContentPlaceHolder1$RadGrid1" and there is no indication if this is export or other action ( I send the insert command using custom button as well)  do  I can't disable the ajax .

Is there a way to overcome this?

1 Answer, 1 is accepted

Sort by
0
Accepted
Casey
Top achievements
Rank 1
answered on 27 Feb 2012, 03:03 PM
Hi Yuval,

Have you tried getting a reference to the AjaxManager instance and then disabling ajax before the call to export to excel?

I believe that the following should accomplish what you are looking for.

I hope this helps!
Casey

function ExportGrid(sender, args) {
    var ajaxMan = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
    ajaxMan.set_enableAjax(false);
    var masterTable = $find("<%=RadGrid1.ClientID %>").get_masterTableView();
    masterTable.exportToExcel();
}

Tags
Grid
Asked by
Yuval
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Share this question
or