How to XslTransform.Transform to new web page from code behind?

J

John Holmes

I'm working with a typed dataset and want to implement a print button that
prints my formatted data without the company logo and other stuff on the
form. I've created an XSLT file to transform the XML version of the dataset
into HTML and would like to display it in a new browser window leaving the
original window up and/or maybe even just send it out to the default printer
or bring up the print dialog for printing out the web page. I have
successfully saved the html file, but I'm not sure how to send to a new
browser window instead of a file. Please help, code below:

XmlDataDocument xmlDoc = new XmlDataDocument(dsAffidavit);
XslTransform xslTran = new XslTransform();
xslTran.Load(Server.MapPath("Affidavit.xslt"));
XmlTextWriter writer = new
XmlTextWriter(@"C:\tmp\Printout.htm,System.Text.Encoding.UTF8);
xslTran.Transform(xmlDoc,null,writer);

John Holmes
(e-mail address removed)
 
J

John Holmes

This works and is great, but I'd like to have it come up in a new browser
window if possible. Everything I've read about the Response object says it's
associated with the current page and I'm not sure how I would open in a new
window. I know how to do this with the javascript window.open method, but
not sure how to do that with c# code behind.

Thanks,

John
 
S

Steven Cheng[MSFT]

Hi John,

Thanks for your response. As for opening a new browser window. This is only
possible to do in clientside script. The serverside code is unable to
perform such function. Generally we used the "Page.RegisterStartupScript()"
function to register a clientside script such as "window.open(..)" at
runtime to simulate the effect. As for your siutation, I think you need to
also register a certain clientside script to open a new browser window at
client. You may build a certain page which only used to show the html
transformed from DataSet. You can used some querystring param in this page
to determine whch datatable to use or how to generate the DataSet and then
use the code we discussed in former messages to transform it and display in
the page.

In addition, if you do think it necessary to generate the dataset in the
original page's postback event, then, you need to store the result dataset
in a session member , and then retrieve it again from the session and
display it. Do you think so?
If you have any other ideas or questions ,please feel free to post here.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top