function onRequestStart(ajaxPanel, eventArgs) { if (eventArgs.EventTarget == "ExportToExcel") { eventArgs.EnableAjax = false; }5 Answers, 1 is accepted
Here is the full code that I tried based on your scenario.
aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="onRequestStart"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="false"> <MasterTableView CommandItemDisplay="Top"> <CommandItemTemplate> <telerik:RadToolBar ID="RadToolBar1" runat="server" OnButtonClick="RadToolBar1_ButtonClick"> <Items> <telerik:RadToolBarButton Text="export"> </telerik:RadToolBarButton> </Items> </telerik:RadToolBar> </CommandItemTemplate> <Columns> <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID"> </telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid>protected void RadToolBar1_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e) { RadGrid1.MasterTableView.ExportToExcel(); }<script type="text/javascript"> function onRequestStart(sender, args) { if (args.get_eventTarget().indexOf("RadToolBar1") >= 0) args.set_enableAjax(false); }</script>Thanks,
Shinu
if (args.get_eventTarget().indexOf("RadToolBar1") >= 0)
args.set_enableAjax(false); Try setting the following.
aspx:
<ExportSettings ExportOnlyData="true"></ExportSettings>Thanks,
Shinu
<CommandItemTemplate> <telerik:RadToolBar ID="RadToolBar1" runat="server" AutoPostBack="true" OnClientButtonClicked="ClientButtonClicked"> <Items> <telerik:RadToolBarButton Text="Edit selected" CommandName="ExportToExcel" CommandArgument="ExportToExcel"> </telerik:RadToolBarButton> <telerik:RadToolBarButton Text="Update" CommandName="jayesh" CommandArgument="jayesh"> </telerik:RadToolBarButton> </Items> </telerik:RadToolBar> </CommandItemTemplate>var IsExport = false; function onRequestStart(sender, args) { if (IsExport == true) { IsExport = false; args.set_enableAjax(false); } } function ClientButtonClicked(sender, args) { if (args.get_item().get_text() == "ExportToExcel") { IsExport = true; } }Thanks,
Jayesh Goyani
Hi Jayesh,
I got the same question, and happened to see this post. I found the get_eventArgument() method at onRequestStart event at the documentation.
However, this method returns the sequence of the RadToolBarButtons. In the provided sample, it returns 1 instead of the CommandArgument. Is there a way to get the commend argument from the args in the onRequestStart event?
Thanks,
Alvin
Hi Alvin,
Can you share some more details on the scenario in which you are facing this behavior? Can you send me the exact setup leading to the issue so I can reproduce and examine it further at my end?
Hi,
What I am trying to do is identify the Export Button in the RadToolBar at onRequestStart event using get_eventArgument().
aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="onRequestStart">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false">
<MasterTableView CommandItemDisplay="Top">
<CommandItemTemplate>
<telerik:RadToolBar ID="RadToolBar1" runat="server">
<Items>
<telerik:RadToolBarButton Text="Add" CommandArgument="Add" ></telerik:RadToolBarButton>
<telerik:RadToolBarButton Text="Delete" CommandArgument="Delete" ></telerik:RadToolBarButton>
<telerik:RadToolBarButton Text="Export" CommandArgument="Export"></telerik:RadToolBarButton>
</Items>
</telerik:RadToolBar>
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
JS:
<script type="text/javascript">
function onRequestStart(sender, args) {
if( args.get_eventArgument()=='3') { // What I want is 'Export', but it returns sequence of the RadToolBarbutton.
args.set_enableAjax(false);
}
}
</script>
Thanks,
Alvin
Hi Alvin,
Thanks a lot for the provided sample.
The get_eventArgument() method of the AjaxManager gets the string passed in the initial AJAX request by the Toolbar that corresponds to the index of the clicked button and does not provide access to the commandArgument of the clicked button.
You can still access the CommandArgument of the clicked button in the Toolbar's OnClientClicked event like suggest by Jayesh above:
<script>
var IsExport = false;
function onRequestStart(sender, args) {
if (IsExport == true) {
IsExport = false;
args.set_enableAjax(false);
}
}
function ClientButtonClicked(sender, args) {
if (args.get_item().get_text() == "Export") {
IsExport = true;
}
}
</script>