I have a standard Radgrid and am using the RadGrid.MasterTableView.ExportToExcel() method. Unfortunately, I have to refresh the page, after an export, in order to do any sorting/filtering or another export. Am I missing something?
Thanks,
Mark
20 Answers, 1 is accepted
I'm not sure what is causing that issue,Please have a look at this code snippet.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
AllowPaging
=
"True"
runat
=
"server"
AutoGenerateColumns
=
"false"
AllowSorting
=
"True"
onitemcommand
=
"RadGrid1_ItemCommand"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
>
<
CommandItemSettings
ShowExportToExcelButton
=
"true"
/>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
HeaderText
=
"First Name"
> </
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExportToExcelCommandName)
{
RadGrid1.ExportSettings.ExportOnlyData =
true
;
RadGrid1.ExportSettings.IgnorePaging =
true
;
RadGrid1.ExportSettings.OpenInNewWindow =
false
;
}
}
Thanks,
Shinu
Thanks for the reply!
It's actually all C# and fired off of a link button. I have tried using the CommandItemSettings method as well with the same results. Does this have something to do with Ajax? Another interesting note is that in either case RadGrid1.ExportingSettings.OpenInNewWindow must be set to true otherwise it will not export at all.
Thanks,
Mark
Please try the following code snippet.Hope this helps you.
ASPX:
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
ClientEvents
OnRequestStart
=
"onRequestStart"
></
ClientEvents
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
></
telerik:AjaxUpdatedControl
>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnItemCommand
=
"RadGrid1_ItemCommand1"
AllowSorting
=
"true"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"OrderID"
CommandItemDisplay
=
"Top"
>
<
CommandItemSettings
ShowExportToExcelButton
=
"true"
ShowAddNewRecordButton
=
"false"
ShowRefreshButton
=
"true"
/>
. . . . . . .
</
MasterTableView
>
</
telerik:RadGrid
>
JS:
<script type=
"text/javascript"
>
function
onRequestStart(sender, args)
{
if
(args.get_eventTarget().indexOf(
"ExportTo"
) >= 0)
{
args.set_enableAjax(
false
);
}
}
</script>
Thanks,
Princy
I actually removed the ajax manager because it appears to slow the solution down significantly. Radgrid response time was improved noticeably. I can re-implement it, but I would prefer to avoid it if at all possible.
Thanks,
Mark
Note that the exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.
Regards,
Kostadin
Telerik
I have tried firing off the export to excel via a link button (C#) and using the Command Item Settings button as well. Both appears to have the same effect. Essentially the grid is unusable until the page is refreshed after the export.
Thanks,
Mark
JS:
<script type=
"text/javascript"
>
function
onRequestStart(sender, args)
{
if
(args.get_eventTarget().indexOf(
"ExportTo"
) >= 0)
{
args.set_enableAjax(
false
);
}
}
</script>
It is definitely getting added and the radgrid is definitely ajaxified, but I am still experiencing the same issue. I can export once and then the radgrid becomes unresponsive until the page is refreshed.
I have even reviewed the following link, and my work is very similar.
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx
Thanks,
Mark
I would ask you to provide us with a code declaration of the problematic page and the related code behind. This way we will be able to investigate the issue locally and provide you with more to the point answer.
Regards,
Kostadin
Telerik
Here is the script that is embedded on the page it is added in the prerender method, When I view source it is included on the page.
private string EmbeddedScriptFormat =
"<
script
type=\"text/javascript\">" + Environment.NewLine +
"function onRequestStart(sender, args)" + Environment.NewLine +
"{" + Environment.NewLine +
"if (args.get_eventTarget().indexOf(\"ExportTo\") >= 0)" + Environment.NewLine +
//"if(args.get_eventTarget().indexOf(\"lbExportToExcel\") >= 0)" + Environment.NewLine +
"{" + Environment.NewLine +
"args.set_enableAjax(false);" + Environment.NewLine +
"}" + Environment.NewLine +
"}" + Environment.NewLine +
"</
script
>";
This is added in the create child controls method in order to associate the RadGrid with the RadAjaxManager.
//Ajaxifying the Radgrid
this.AjaxManager.ClientEvents.OnRequestStart = "onRequestStart";
AjaxSetting ajaxSetting = new AjaxSetting();
ajaxSetting.AjaxControlID = this.rgTest.ID;
AjaxUpdatedControl ajaxUpdatedControl = new AjaxUpdatedControl();
ajaxUpdatedControl.ControlID = this.rgTest.ID;
ajaxSetting.UpdatedControls.Add(ajaxUpdatedControl);
this.AjaxManager.AjaxSettings.Add(ajaxSetting);
The Export to Excel function is called through a C# LinkButton.
The RadAjaxManager is setup in the OnInit method. Please let me know if you need more code.
Thanks,
Mark
Could you please confirm that the export functionality works as expected when the ajax is disabled? Additionally could you please make sure that the ajax is disabled properly by onRequestStart function? The provided code looks correct so I will need the entire code declaration and code behind of the page for further investigation.
Regards,
Kostadin
Telerik
How would I got about testing whether onRequestStart actually disabled Ajax properly? I do see the function on the page when I view source.
Here is the Export To Excel link button code if it is helpful:
void
lbExportToExcel_Click(
object
sender, EventArgs e)
{
if
(
this
.chbxExportPaging.Checked)
{
this
.rgTest.ExportSettings.IgnorePaging =
true
;
}
else
{
this
.rgTest.ExportSettings.IgnorePaging =
false
;
}
this
.rgTest.ExportSettings.OpenInNewWindow =
true
;
this
.rgTest.ExportSettings.ExportOnlyData =
true
;
this
.rgTest.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
this
.rgTest.MasterTableView.ExportToExcel();
}
Thanks,
Mark
You could add a break point or write a debugger; into your javascript function. Check out the following code snippet.
private string EmbeddedScriptFormat =
"<script type=\"text/javascript\">"
+ Environment.NewLine +
"function onRequestStart(sender, args)"
+ Environment.NewLine +
"{ debugger;"
+ Environment.NewLine +
"if (args.get_eventTarget().indexOf(\"ExportTo\") >= 0)"
+ Environment.NewLine +
//"if(args.get_eventTarget().indexOf(\"lbExportToExcel\") >= 0)" + Environment.NewLine +
"{"
+ Environment.NewLine +
"args.set_enableAjax(false);"
+ Environment.NewLine +
"}"
+ Environment.NewLine +
"}"
+ Environment.NewLine +
"</script>"
;
This way you will be able to check whether the ajax is disabled or not.
Regards,
Kostadin
Telerik
Thanks!
Add the following script to your webpart / custom control:
<script type=
"text/javascript"
language=
"javascript"
>
//sharepoint postback to work after clicking on telerik export to pdf
if
(
typeof
(_spBodyOnLoadFunctionNames) !=
'undefined'
&& _spBodyOnLoadFunctionNames !=
null
) {
_spBodyOnLoadFunctionNames.push(
"supressSubmitWraper"
);
}
function
supressSubmitWraper() {
_spSuppressFormOnSubmitWrapper =
true
;
}
</script>
-Mark
Thanks Mark, I used the 3rd option in your referenced link and that worked like a charm!
For the benefit of anyone else reading this post, we faced this issue when using in 2015 Q1 version of Telerik suite of controls.
NOTE: I'm not saying that this is an issue with the Telerik suite of controls, but just specifying my operating environment for the benefit of those reading this post...
Raj
The Export to excel functionality which is successfully working in all browsers is getting failed in Edge browser for some reason,
Iam using RadGrid.MasterTableView.ExportToExcel() ..
Can some one figure out what could be the issue
Well, what if you're not in SharePoint and you need to refresh the page after exporting? Here's what works for me:
function
OnClientClose(oWnd, args) {
//get the transferred arguments
if
(oWnd.get_name() ==
'RadExportWindow'
&& args) {
document.getElementById(
'<%= hdnExport.ClientID %>'
).value = args._argument.ExportText;
setTimeout(
'ForcePostback();'
, 5000);
__doPostBack(
''
,
'Export'
);
}
return
false
}
function
ForcePostback() {
__doPostBack(
''
,
'Refresh'
);
}
Have you tried to reproduce the issue on the online demos?
Export to Excel demo
If you believe you have found a bug you can submit a regular support ticket with a sample project so that we can debug it locally.
Regards,
Daniel
Telerik
Mark, your solution finalliy worked for me as welll.
<script type="text/javascript" language="javascript">
//sharepoint postback to work after clicking on telerik export to pdf
if (typeof (_spBodyOnLoadFunctionNames) != 'undefined' && _spBodyOnLoadFunctionNames != null) {
_spBodyOnLoadFunctionNames.push("supressSubmitWraper");
}
function supressSubmitWraper() {
_spSuppressFormOnSubmitWrapper = true;
}
</script>
Thanks,