Hello,
The business requirements for my application require the use of modal windows due to the process involved in calculating commissions correctly. The problem I'm having is exporting to Excel when <base target="_self"> is included in the head tag of the page. Unfortunately, I've found that I need to include it in order for the grid to be grouped or ungrouped in the same window, the dialog window to be closed, or the grid to be updated in the same window (i.e., display a row in red when updated through a button).
In order to attempt to solve the problem, I've tried the various export modes along with a JavaScript function found when researching. So far, nothing is working. I've also changed to a modeless window and, although it works, I need to comply with the business requirements.
I would appreciate any help in getting grid results successfully exported to Excel from a modal window with <base target="_self"> in the head tag. I'm including the definition of the grid and the code for exporting below.
Thanks and have a great day!
Pat
<igtbl:UltraWebGrid ID="grdPreviewDetails" runat="server" Height="450px"
onungroupcolumn="grdPreviewDetails_UnGroupColumn"
oninitializerow="grdPreviewDetails_InitializeRow">
<Bands>
<igtbl:UltraGridBand BaseTableName="grdPreviewDetails" Key="key">
<AddNewRow Visible="NotSet" View="NotSet"></AddNewRow>
<Columns>
<igtbl:UltraGridColumn BaseColumnName="key" HeaderText="" Hidden="True" Key="key">
<Header Caption="">
</Header>
</igtbl:UltraGridColumn>
<igtbl:TemplatedColumn AllowGroupBy="No" AllowUpdate="Yes" BaseColumnName="Checked"
HeaderText="" Key="Checked" SortIndicator="Disabled" Type="CheckBox">
<Header Caption="Hold?">
<RowLayoutColumnInfo OriginX="1" />
<CellStyle HorizontalAlign="Center">
</CellStyle>
<Footer>
</Footer>
</igtbl:TemplatedColumn>
</Columns>
</igtbl:UltraGridBand>
</Bands>
AllowSortingDefault="OnClient" AllowDeleteDefault="Yes"
TableLayout="Fixed" ViewType="OutlookGroupBy" RowSelectorsDefault="No"
StationaryMargins="Header" BorderCollapseDefault="Separate"
NoDataMessage="There are no payments to preview" IndentationDefault="0"
GroupByRowDescriptionMaskDefault="[caption] : [value] ([count]; [sum:AmountPaid])">
<Style BackColor="ActiveBorder" BorderColor="Window"></Style>
<FrameStyle BackColor="Window" BorderColor="InactiveCaption" BorderWidth="1px"
Height="450px" Width="797px"></FrameStyle>
InitializeLayoutHandler="grdPreviewDetails_InitializeLayoutHandler" />
<Style BackColor="LightGray" BorderWidth="1px" BorderStyle="Solid">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px"></BorderDetails>
</Pager>
<FooterStyleDefault BackColor="LightGray" BorderWidth="1px" BorderStyle="Solid">
</FooterStyleDefault>
<RowStyleDefault BackColor="Window" BorderColor="Silver" BorderWidth="1px" BorderStyle="Solid">
<BorderDetails ColorLeft="Window" ColorTop="Window"></BorderDetails>
<GroupByRowStyleDefault BackColor="Control" BorderColor="Window"></GroupByRowStyleDefault>
<Style BackColor="Window" BorderColor="InactiveCaption" BorderWidth="1px" BorderStyle="Solid">
</AddNewBox>
<FilterDropDownStyle CustomRules="overflow:auto;" BackColor="White" BorderColor="Silver" BorderWidth="1px" BorderStyle="Solid" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px" Height="300px" Width="200px">
</FilterDropDownStyle>
</FilterOptionsDefault>
</DisplayLayout>
</igtbl:UltraWebGrid>
<div id="divExport" style="z-index: 107; left: 12px; width: 479px; position: absolute;
top: 566px; height: 53px">
EnableViewState="false" oninitializecolumn="UltraWebGridExcelExporter1_InitializeColumn" >
</cc1:UltraWebGridExcelExporter>
</div>
{
string strMonth = System.DateTime.Today.Month.ToString();
//Add leading zero if month is single digit
}
//Add leading zero if day is single digit
grdPreviewDetails.Columns.FromKey("AmountPaid").HeaderText = "Payment";
grdPreviewDetails.Columns.FromKey("AmountPaid").Format = "C"; //To ensure the export retains the currency format, set the value to "C" here; it is checked/set in the InitializeColumn function.
UltraWebGridExcelExporter1.DownloadName = strFileName;
UltraWebGridExcelExporter1.Export(grdPreviewDetails); //,strFileName
The main page contains a button which displays the dialog window. The javascript called by the button click event is:
//It was necessary to include the resizeGrid() function here to prevent the grid from displaying at the top of the page over other controls
//The resizeGrid() function resizes the grid based on the user's screen resolution
resizeGrid()
var openString = "wfDialogContainer.aspx?draws=" + includeDraws
The dialog container page contains (note the iframe dimensions are the same as defined in the featurestring above):
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="wfDialogContainer.aspx.cs" Inherits="FIS.CommissionManagement.ClientLayer.CommissionManagement.WebForms.wfDialogContainer" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
</head>
<body>
<form id="frmDialogContainer" runat="server">
<div>
This container page was created to house dialog windows in which the data needs to be exported to Excel; the
<base target="_self"> tag is necessary in a dialog window for any postbacks that are necessary. However, this
tag prevents the export to Excel. Research resulted in finding this method which works as required.
Note that code/parameters may need to be changed based on the source page of the iframe.
-->
<iframe id="DialogContainer" runat="server" frameborder="0" scrolling="no" style="position: absolute; height: 690px; width: 825px;"></iframe>
</body>
</html>
The code-behind contains:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class wfDialogContainer : System.Web.UI.Page
So far, this is the only page I have that needs this method. In the future, the code-behind may need to be adapted for other sources.
Hope this helps solve your problem!
Hi,
i got the same problem, can you please send me your solution with more details.
I found a solution that works as I need it to. The modal window calls a page that contains only an iframe with a little bit of code to handle any parameters needing to be passed. The source of the iframe is then set in code to display the actual page. I have three buttons on the page with one of them doing a postback which goes to the same modal window. The excel export button performs as expected with only the Open/Save dialog being displayed. Clicking the Open selection opens Excel and displays the results while clicking the Save selection prompts the user for a location.
Neither the iframe page or the actual page require the <base target="_self"> tag.
As a side note, we are using version 6.3 and, from what I can tell, the WebDialogWindow is not available.
Thank you for the suggestions. I have tried the exportmode.custom method without much success. Do you have an easy-to-follow/understand sample? One thing I need to make sure of is to allow the user to save the worksheet to a place of their choice.
I'll try the hyperlink suggestion and see where that takes me.
pgrimes629 said: I would appreciate any help in getting grid results successfully exported to Excel from a modal window with <base target="_self"> in the head tag.
I seem to recall some browsers faced challenges, at least in the past, when opening an Excel file from within a window created via showModal( ). If you put an ordinary hyperlink on this page to a temporary .xls (not one produced by the exporter, just save an empty workbook from Excel) that is being hosted at some path on your Web server, and you click on this hyperlink - does it download/open successfully within the modal window?
If so, then at least one approach you should be able to use is ExportMode.Custom and then arrange for the file stream so created and stored temporarily on the server to be downloaded by the modal window. If the hyperlink test doesn't work then you'll know the challenge isn't with the WebGridExcelExporter, but the modal window opening of an Excel file limitation.
The above assumes you're using showModal( ) or something similar to create this window and perhaps that isn't the case. The WebDialogWindow control supports a modal display mode that prevents interaction by the user with the browser contents in the background, have you tried exporting the grid using a WebDialogWindow?