I have a rad grid that is AJAXified through a RadAjaxManager and I use a javascript function to stop the async request so I can export. This works perfectly in Chrome and Firefox. But does not seem to work in internet explorer. The page just refreshes. Any workarounds to this?
The rest of the columns are created programmatically on the first page load as some of the grid bound columns implement custom filters for google-like filtering and some are dropdownlists etc.
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
script
type
=
"text/javascript"
>
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initRequest);
function initRequest(sender, args) {
if (args.get_postBackElement().id.indexOf("btn_ExcelExport") != -1) {
args.set_cancel(true); //stop async request
sender._form["__EVENTTARGET"].value = args.get_postBackElement().id.replace(/\_/g, "$");
sender._form["__EVENTARGUMENT"].value = "";
sender._form.submit();
return;
}
}
</
script
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"rg_Clients"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"rg_Clients"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadGrid
ID
=
"rg_Clients"
runat
=
"server"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
ActiveItemStyle-BackColor
=
"#004070"
ActiveItemStyle-ForeColor
=
"White"
AllowSorting
=
"True"
CellSpacing
=
"0"
GridLines
=
"Both"
OnNeedDataSource
=
"rg_Clients_NeedDataSource"
Skin
=
"WebBlue"
OnItemCommand
=
"rg_Clients_ItemCommand"
AutoGenerateColumns
=
"false"
EnableLinqExpressions
=
"false"
HeaderStyle-Font-Bold
=
"true"
OnColumnCreating
=
"rg_Clients_ColumnCreating"
GroupingSettings-CaseSensitive
=
"false"
OnPreRender
=
"rg_Clients_PreRender"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
AllowFilteringByColumn
=
"True"
>
<
Columns
>
<
telerik:GridTemplateColumn
AllowFiltering
=
"false"
UniqueName
=
"ClientID"
HeaderStyle-Width
=
"40px"
ItemStyle-HorizontalAlign
=
"Left"
HeaderStyle-HorizontalAlign
=
"Left"
>
<
HeaderTemplate
>
<
asp:ImageButton
ID
=
"btn_ExcelExport"
runat
=
"server"
ImageUrl
=
"~/Images/Excel-icon.png"
Width
=
"30"
Height
=
"30"
OnClick
=
"btn_ExcelExport_Click"
CausesValidation
=
"false"
/>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:Button
ID
=
"btn_View"
CommandName
=
"Select"
CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ClientID") %>'
runat="server" Text="View" />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
<
ExportSettings
Excel-Format
=
"ExcelML"
FileName
=
"ClientExport"
IgnorePaging
=
"true"
OpenInNewWindow
=
"true"
ExportOnlyData
=
"true"
/>
</
telerik:RadGrid
>
protected
void
btn_ExcelExport_Click(
object
sender, ImageClickEventArgs e)
{
string
[] UserRoles = Roles.GetRolesForUser();
rg_Clients.MasterTableView.GetColumn(
"ClientID"
).Visible =
false
;
//Dont need to see the filter boxes in the excel sheet
foreach
(GridFilteringItem Filter
in
rg_Clients.MasterTableView.GetItems(GridItemType.FilteringItem))
Filter.Visible =
false
;
//Data Admin and Site Admin can export all Clients, Sales Admin can export their own and who they are supervising,
// and Sales Person can only export their own
if
(UserRoles.Contains(
"Sales Admin"
))
{
string
Source = PageController.GetUserFullName((Guid)Membership.GetUser().ProviderUserKey);
List<
string
> Sources = ClientController.GetSupervisorSources((Guid)Membership.GetUser().ProviderUserKey);
if
(rg_Clients.MasterTableView.FilterExpression != String.Empty)
rg_Clients.MasterTableView.FilterExpression +=
"AND "
;
string
QueryFilter =
"([Sources] LIKE \'%"
+ Source +
"%\') "
;
foreach
(
string
S
in
Sources)
QueryFilter +=
"OR ([Sources] LIKE \'%"
+ S +
"%\') "
;
rg_Clients.MasterTableView.FilterExpression += QueryFilter;
}
else
if
(UserRoles.Contains(
"Sales Person"
))
{
string
Source = PageController.GetUserFullName((Guid)Membership.GetUser().ProviderUserKey);
if
(rg_Clients.MasterTableView.FilterExpression != String.Empty)
rg_Clients.MasterTableView.FilterExpression +=
"AND "
;
rg_Clients.MasterTableView.FilterExpression +=
"([Sources] LIKE \'%"
+ Source +
"%\') "
;
}
rg_Clients.MasterTableView.ExportToExcel();
The rest of the columns are created programmatically on the first page load as some of the grid bound columns implement custom filters for google-like filtering and some are dropdownlists etc.