Export Excel Question

G

Guest

Hi all,

I have a parent page(parent.aspx) which will open different new windows
depending on the user input.

for example,
the new windows are opened using the following code :
window.open('child.aspx', document.userinput.value)

In the child.aspx, the result is rendered as Excel, Word, PDF, etc...
depending on the input parameters from the parent pages.

There is no problem when the user just open 1 pop up window.
However, when the user first open a Excel Window, and then open another
window (Word) , the first window will become blank. Then the result in the
second window
will become the result in first window (Excel).

Thank You.
 
G

Guest

Here are the sample codes.
Parent.html :

<html>
<head>
<script language=javascript>
function OpenWindow()
{
var oWnd = window.open('', document.frmOption.selOption.value);
document.frmOption.target = document.frmOption.selOption.value;
document.frmOption.submit();

}
</script>
</head>
<body>
<form id=frmOption name=frmOption method=post action="child.aspx">
<select id=selOption name=selOption>
<option value=1>Excel</option>
<option value=2>Word</option>
</select>
<input type=button value="Open Window" onclick="OpenWindow()">
</form>
</body>
</html>

Put the following code in Child.aspx :
c#

if (Request["selOption"].ToString().Trim() == "1")
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition",
"inline;filename=excel.xls");
Response.Write("This is Excel");
}
else
{
Response.ContentType = "application/vnd.msword";
Response.AddHeader("Content-Disposition",
"inline;filename=word.doc");
Response.Write("This is Word");
}
Response.End();


vb.net

if Request("selOption").ToString().Trim() = "1" Then
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition",
"inline;filename=excel.xls")
Response.Write("This is Excel")
else
Response.ContentType = "application/vnd.msword"
Response.AddHeader("Content-Disposition",
"inline;filename=word.doc")
Response.Write("This is Word")
end if
Response.End()
 

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

Top