My application produces a very large report that has the requirement of being exported (Excel, PDF, CSV). From reading several threads here about problems with exporting large files and running into the issue myself, I took the approach to limit what is being exported by changing the page size and setting Ignorepaging to false. What I'd like to do is post back an message/alert something to the user to let them know that what they tried to export was too large and the records were limited to x number. My problem is that no matter what I've tried a message doesn't get displayed. My app has user control on the page that is meant to display messages that isn't working (pgMessage in code). I've tried adding a literal control to the bottom of the Grid as suggested in a form thread. That didn't work, I've tried using RegisterStartupscript with an alert. That hasn't worked. I've moved all of the above to different events like ItemCommand, Exporting, Pre_Render but I haven't found any that works. My grid is ajaxified and I've followed the manuals approach on exporting an ajaxified grid.
Any one have any suggestions?
ASPX:
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="lnkbtnSave"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="rcbRptSettings" |
LoadingPanelID="" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="lnkbtnSaveAs"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="rcbRptSettings" |
LoadingPanelID="" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="rcbRptSettings"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="rcbRptSettings" /> |
<telerik:AjaxUpdatedControl ControlID="rdpbegin" UpdatePanelRenderMode="Inline" /> |
<telerik:AjaxUpdatedControl ControlID="rdpend" UpdatePanelRenderMode="Inline" /> |
<telerik:AjaxUpdatedControl ControlID="rcbCodeList" /> |
<telerik:AjaxUpdatedControl ControlID="rcbListType" /> |
<telerik:AjaxUpdatedControl ControlID="rtbCode" /> |
<telerik:AjaxUpdatedControl ControlID="btnAddCode" /> |
<telerik:AjaxUpdatedControl ControlID="rlbCodes" /> |
<telerik:AjaxUpdatedControl ControlID="rlbFields" /> |
<telerik:AjaxUpdatedControl ControlID="rcbGroupSort" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="rcbCodeList"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="rcbListType" |
LoadingPanelID="RadAjaxLoadingPanel1" /> |
<telerik:AjaxUpdatedControl ControlID="rtbCode" /> |
<telerik:AjaxUpdatedControl ControlID="btnAddCode" /> |
<telerik:AjaxUpdatedControl ControlID="rlbCodes" |
LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="rcbListType"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="rtbCode" /> |
<telerik:AjaxUpdatedControl ControlID="btnAddCode" /> |
<telerik:AjaxUpdatedControl ControlID="rlbCodes" |
LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="btnAddCode"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="rtbCode" |
LoadingPanelID="RadAjaxLoadingPanel1" /> |
<telerik:AjaxUpdatedControl ControlID="rlbCodes" |
LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="btnSearch"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="lnkbtnSave" /> |
<telerik:AjaxUpdatedControl ControlID="lnkbtnSaveAs" /> |
<telerik:AjaxUpdatedControl ControlID="ARGrid1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="btnReset"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="rdpbegin" UpdatePanelRenderMode="Inline" /> |
<telerik:AjaxUpdatedControl ControlID="rdpend" UpdatePanelRenderMode="Inline" /> |
<telerik:AjaxUpdatedControl ControlID="rcbCodeList" /> |
<telerik:AjaxUpdatedControl ControlID="rcbListType" /> |
<telerik:AjaxUpdatedControl ControlID="rtbCode" /> |
<telerik:AjaxUpdatedControl ControlID="btnAddCode" /> |
<telerik:AjaxUpdatedControl ControlID="rlbCodes" /> |
<telerik:AjaxUpdatedControl ControlID="rlbFields" /> |
<telerik:AjaxUpdatedControl ControlID="rcbGroupSort" /> |
<telerik:AjaxUpdatedControl ControlID="ARGrid1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="ARGrid1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="ARGrid1" |
LoadingPanelID="RadAjaxLoadingPanel1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManagerProxy> |
...... |
<pm:PgMsg ID="PgMessage" runat="server" /> |
...... |
<telerik:RadGrid ID="ARGrid1" runat="server" Width="97%" Height="95%" GridLines="None" PageSize="40" EnableAjaxSkinRendering="true" |
AllowSorting="true" AllowPaging="true" Visible="false" OnNeedDataSource="ARGrid1_NeedDataSource" OnItemCreated="ARGrid1_ItemCreated" |
OnItemCommand="ARGrid1_ItemCommand" OnGridExporting="ARGrid1_Exporting" ShowStatusBar="true" ShowGroupPanel="true" Skin="Outlook"> |
<MasterTableView AllowFilteringByColumn="true" AllowMultiColumnSorting="true" Width="100%" CommandItemDisplay="Top" ShowGroupFooter="false" AutoGenerateColumns="true"> |
<HeaderStyle Width="200px" /> |
<Columns></Columns> |
<CommandItemSettings AddNewRecordText="" ShowExportToPdfButton="true" ShowExportToWordButton="true" ShowExportToExcelButton="true" ShowExportToCsvButton="true" /> |
</MasterTableView> |
<ClientSettings AllowColumnsReorder="true" AllowDragToGroup="true" ColumnsReorderMethod="Reorder" EnableRowHoverStyle="true"> |
<Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="false" FrozenColumnsCount="0" ScrollHeight="100%" /> |
<Resizing ClipCellContentOnResize="false" AllowColumnResize="true" /> |
</ClientSettings> |
<GroupingSettings ShowUnGroupButton="true" RetainGroupFootersVisibility="false" /> |
<ExportSettings IgnorePaging="true" OpenInNewWindow="true"> |
<Pdf AllowPrinting="true" /> |
</ExportSettings> |
</telerik:RadGrid> |
function onRequestStart(ajaxManager, eventArgs) {
if ((eventArgs.EventTarget == "ARGrid1") && (cancelAjax)) {
eventArgs.EnableAjax = false;
}
//Uncomment the line below in case of a file download.
//cancelAjax = false;
if (eventArgs.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
eventArgs.get_eventTarget().indexOf( "ExportToWordButton") >= 0 ||
eventArgs.get_eventTarget().indexOf( "ExportToPdfButton") >= 0 ||
eventArgs.get_eventTarget().indexOf( "ExportToCsvButton") >= 0) {
eventArgs.set_enableAjax( false);
}
//Used to display ajax graphic(twirly) over gridPane
currentLoadingPanel = $find( "<%= RadAjaxLoadingPanel1.ClientID %>");
if (eventArgs.get_eventTarget() == "<%= btnSearch.UniqueID %>") {
currentUpdatedControl = "<%= gridPane.ClientID %>";
}
//show the loading panel over the updated control
currentLoadingPanel.show(currentUpdatedControl);
} |
CodeBehind: I've commented out most to the code I've tried. The last attempt was with RegisterStartupScript.
protected void Page_PreRender(object sender, EventArgs e) |
{ |
//if (exportMsg != string.Empty) |
//{ |
// PgMessage.DisplayMessage(PageMessage.MessageType.Information, exportMsg); |
// exportMsg = string.Empty; |
//} |
ARGrid1.EnableAjaxSkinRendering = true; |
} |
protected void Page_Load(object sender, EventArgs e) |
{ |
//Set up client side calls for AjaxProxyManager |
RadAjaxManager manager = RadAjaxManager.GetCurrent(Page); |
manager.ClientEvents.OnRequestStart = "onRequestStart"; |
manager.ClientEvents.OnResponseEnd = "onResponseEnd"; |
manager.AjaxSettingCreated += new RadAjaxControl.AjaxSettingCreatedDelegate(manager_AjaxSettingCreated); |
manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(manager_AjaxRequest); |
//Ajaxify user control for controls |
Control mainPlaceHolder = Master.FindControl("MainPH"); |
Control pgMsg = mainPlaceHolder.FindControl("pgMessage"); |
RadAjaxLoadingPanel ajaxLoadingPanel = Master.FindControl("RadAjaxLoadingPanel1") as RadAjaxLoadingPanel; |
manager.AjaxSettings.AddAjaxSetting(btnSearch, pgMsg, ajaxLoadingPanel); |
manager.AjaxSettings.AddAjaxSetting(btnAddCode, pgMsg, ajaxLoadingPanel); |
manager.AjaxSettings.AddAjaxSetting(lnkbtnSave, pgMsg, ajaxLoadingPanel); |
manager.AjaxSettings.AddAjaxSetting(lnkbtnSaveAs, pgMsg, ajaxLoadingPanel); |
manager.AjaxSettings.AddAjaxSetting(btnReset, pgMsg, ajaxLoadingPanel); |
manager.AjaxSettings.AddAjaxSetting(ARGrid1, pgMsg, ajaxLoadingPanel); |
PgMessage.ClearMessages(); |
//Render user control |
if (!Page.IsPostBack) |
{ |
BindSavedSettings(Master.loggedUser.UserReports); |
BindCodeList(); |
BindListType(); |
BuildFieldList(); |
} |
//RadComboBox1.Items.Add(new RadComboBoxItem("Add Item","Add Item")); |
} |
protected void ARGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) |
{ |
if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName || |
e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName || |
e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName || |
e.CommandName == Telerik.Web.UI.RadGrid.ExportToPdfCommandName) |
{ |
ConfigureExport(); |
} |
} |
private void DisplayMessageInRadGrid(string text) |
{ |
// This places a nicely formatted message in the bottom row of the grid |
ARGrid1.Controls.Add(new LiteralControl(text)); |
} |
public void ConfigureExport() |
{ |
//int gridCount = 0; |
////Get the total number of rows in the grid. (Should take into account filters) Done this way per Telerik. Otherwise only get current pagesize |
//ARGrid1.AllowPaging = false; |
//ARGrid1.Rebind(); |
//gridCount = ARGrid1.MasterTableView.Items.Count; |
//ARGrid1.AllowPaging = true; |
//ARGrid1.Rebind(); |
ARGrid1.ExportSettings.ExportOnlyData = true; //CheckBox1.Checked; |
ARGrid1.ExportSettings.OpenInNewWindow = true; //CheckBox3.Checked; |
if ((int)Session["itemsCount"] > 2000) |
{ |
exportMsg = "Export exceeds record limit. Export was cut to 2000 records"; |
//DisplayMessageInRadGrid(exportMsg); |
//PgMessage.DisplayMessage(PageMessage.MessageType.Information, "Export exceeds record limit. Export was cut to 2000 records"); |
//***** |
//*********************************************************** |
//Build cooresponding java script functions |
//*********************************************************** |
// Get a ClientScriptManager reference from the Page class. |
Type cstype = this.GetType(); |
ClientScriptManager cs = Page.ClientScript; |
// Check to see if the startup script is already registered. |
if (!cs.IsStartupScriptRegistered(cstype, "returnScript")) |
{ |
//Build code to post back save/cancel button clicks |
System.Text.StringBuilder cstext = new System.Text.StringBuilder(); |
cstext.AppendLine("<script type=\"text/javascript\">"); |
cstext.AppendLine("alert('" + exportMsg + "');"); |
cstext.AppendLine("</script>"); |
cs.RegisterStartupScript(cstype, "returnScript", cstext.ToString(), false); |
} |
//******* |
DisplayMessageInRadGrid(exportMsg); |
ARGrid1.ExportSettings.IgnorePaging = false; //CheckBox2.Checked; |
ARGrid1.PageSize = 2000; |
ARGrid1.Rebind(); |
} |
else |
{ |
ARGrid1.ExportSettings.IgnorePaging = true; //CheckBox2.Checked; |
} |
} |
protected void ARGrid1_Exporting(object source, Telerik.Web.UI.GridExportingArgs e) |
{ |
isExport = true; //sets exporting to true |
//if (isExport && exportMsg != string.Empty) |
//{ |
// PgMessage.DisplayMessage(PageMessage.MessageType.Information, exportMsg); |
// exportMsg = string.Empty; |
//} |
} |