Showing posts with label built. Show all posts
Showing posts with label built. Show all posts

Saturday, March 24, 2012

triggering an export of Excel content through Atlas

I built an Atlas-enabled form. Depending on an input parameter, I need to either display the output data in HTML or push an Excel stream to the browser. The former is accomplished beautifully with the UpdatePanel; however, I am struggling to figure out the latter. The folowing code works as desired (it results in the browser opening the "File Download" dialogue that allows users to Save or Open the file) with the "regular" postback:

 Response.ContentType ="application/xls"; Response.AddHeader("content-disposition", GetExportFileName("Excel")); XlsExport xls =new XlsExport(); xls.Export(report.Document, memStream); Response.BinaryWrite(memStream.ToArray()); Response.End()

What do I need to do to accomplish this behavior with Atlas?

Thanks a lot!

hello.

can you do that on an external window? ex.: a button click opens a window which targets a handler that returns the response you've shown in the previous post...


Unfortunately, I am not allowed to open an external window.

I was allowed to implement the obvious workaround: save Excel file to disk, put another UpdatePanel on this page, and then display the download link once the file becomes available; however I would rather avoid having to maintain hard copies of the files...


How about an IFRAME with the Excel content type?


I must admit my ignorance: I have not worked with IFrames before. I started reading just now, and it looks like it might be a good solution - if there is a way to close the IFRAME once the user sees the "Save as/Open" dialogue. I will research this further...

If you know of a good working sample online, please let me know.

Thanks a lot!


hello.

hum...i think you're in luck since you can set the src dinamically and event its display is set to none, you'll have the downlod. test this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<iframe id="frm" style="display: none"></iframe>
<hr />
<input type="button" value="donwload" onclick="download()" />

<script type="text/javascript">
function download()
{
document.getElementById("frm").src = "eula.rtf";
}
</script>
</body>
</html>


I am sorry it took me a while to reply - I am in the final stretch of a project...

I managed to build a prototype based on Luis' suggestion; however, there is one problem with this approach: if a user clicks on "Open" button of the "Save as/Open" IE dialogue, then the file may open not in a new instance of the Excel, but in the transparent iframe - and hence be invisible to the user. This wouldn't be an issue had the response been written to a new browser window instead of the iframe, but in my case it wasn't an option.

In the end I simply ran out of time to play around and put in the workaround I described a couple of posts ago.

Thanks a lot for everybody's help!

Triggering Update Panel from Dynamically Built Triggers

I have a page which has two content areas (Left, Center). The Left hand content contains two repeaters, both of which have an imagebutton who's itemcommand triggers an update of the content in the Center area. The Center Area has an update panel in it. The triggers are dynamically generated because the repeaters are in panels, and I needed to use the findcontrol() command to get access to them.

Code works great on my laptop (localhost), gives an error when I move it to the server. Error is:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing this request on the server. The status code returned from the server was: 500.

Here's my UpdatePanel:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Repeater ID="rMain" DataSourceID="srcMain" OnItemCommand="rmain_itemCommand" runat="server"> <ItemTemplate> <asp:Label ID="lblTitle" Text='<%#Eval("Description")%>' runat="server" CssClass="verorangeHeader" /><asp:Label ID="ProductID" runat="server" Text='<%# Eval("idProduct") %>' Visible="false"></asp:Label><asp:Label ID="lblSKU" runat="server" Text='<%# Eval("Sku") %>' Visible="False" /><br /><br /> <table border="0" cellpadding="1" cellspacing="1"> <tr> <td > <asp:Label ID="lblDetails" Text='<%#Eval("Details")%>' runat="server" CssClass="ver11bluebold" /> </td> <td ><img src='<%# formatPhoto(Eval("ImageURL")) %>' /></td> </tr> <tr> <td colspan="2" align="right" valign="top">Priced from: <asp:Label ID="lblPrice" Text='<%# formatPrice(Eval("Price")) %>' runat="server" CssClass="verorange" />   <asp:ImageButton ID="btnSpecifications" ImageURL="images/btn_specifications.gif" runat="server" /><asp:ImageButton ID="btnPhotoGallery" ImageURL="images/btn_photo-gallery.gif" runat="server" /><asp:ImageButton ID="btnBuyNow" ImageURL="images/buy-bm-clear.gif" runat="server" CommandName="Update" /></td> </tr> </table></ItemTemplate></asp:Repeater></ContentTemplate></asp:UpdatePanel>

Here's the code that creates the triggers:

Private Sub Page_Init(ByVal senderAs Object,ByVal eAs EventArgs)Handles MyBase.Init'Add TriggersDim ap1As AsyncPostBackTrigger =New AsyncPostBackTrigger()Dim ap2As AsyncPostBackTrigger =New AsyncPostBackTrigger() ap1.ControlID = pnlProduct1.FindControl("rY5").UniqueID ap1.EventName ="ItemCommand" ap2.ControlID = pnlProduct2.FindControl("r52").UniqueID ap2.EventName ="ItemCommand" UpdatePanel1.Triggers.Add(ap1) UpdatePanel1.Triggers.Add(ap2)End Sub

Any suggestions?

Jennifer

Take a look at this post...http://forums.asp.net/p/1139950/1831145.aspx

-Damien


Got it fixed. It was actually related to a bug in my Master Page!

Thanks for the help!

Jennifer


To fix this problem, you can add the follow code in your web.config

<system.web>
<pages validateRequest="false">
</system.web>.