By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,214 Members | 2,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,214 IT Pros & Developers. It's quick & easy.

Reload calling page in ASP.NET 2.0

P: n/a
Hi

I have a list on LinkButton controls on a page. When the link is clicked the
LinkButton.Command event does a Server.Transfer to a page which writes
binary to the HTTP output stream, e.g. a word document, pdf etc.

Response.BinaryWrite(buffer);
Response.End();

I would like to reload the page with the LinkButtons after this event to
reflect changes which are made after the download of the file.

I understand that some client script may be needed but I'm not sure how to
implement this or if something can be added to the LinkButton.OnClientClick
property.

I'm guessing that maybe I need to do a postback and then write some client
script to open the download page? What's the neatest solution please?

Many thanks
Andrew
Jun 5 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Andrew,

When the LinkButton is clicked, in its Command event, you don't use
Server.Transfer; instead, you use ClientScript.RegisterStartupScript to
register a script to open the download page in a new window:

void Link1_Command(object sender, CommandEventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "download",
"window.open('Download.aspx', '_blank')", true);
}
#open Method (window)
http://msdn2.microsoft.com/en-us/library/ms536651.aspx
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 6 '07 #2

P: n/a
I think your idea will be the easiest: on click of the link button on the
server side, do all the necessary updates and spit out JavaScript code to
open the binary streaming page. This will let the download start in another
page but at the same time refresh the current page.

"J055" wrote:
Hi

I have a list on LinkButton controls on a page. When the link is clicked the
LinkButton.Command event does a Server.Transfer to a page which writes
binary to the HTTP output stream, e.g. a word document, pdf etc.

Response.BinaryWrite(buffer);
Response.End();

I would like to reload the page with the LinkButtons after this event to
reflect changes which are made after the download of the file.

I understand that some client script may be needed but I'm not sure how to
implement this or if something can be added to the LinkButton.OnClientClick
property.

I'm guessing that maybe I need to do a postback and then write some client
script to open the download page? What's the neatest solution please?

Many thanks
Andrew
Jun 6 '07 #3

P: n/a
Hi

Thanks for the advise. I need to include some querystring parameters. The
window.open method doesn't seem to support a querystring, e.g.

onclick="window.open('Download.aspx?ID=1234');"

I guess i need a javascript function? How would I add the function to the
aspx page?

Thanks
Andrew
Jun 6 '07 #4

P: n/a
Hi Andrew,

The window.open function can open a URL with querystring; your code looks
fine, I'm not sure what's the issue you're having?

To add a javascript function in the page, you can use
ClientScript.RegisterClientScriptBlock or
ClientScript.RegisterClientScriptBlock.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 7 '07 #5

P: n/a
Hi Walter

There's a problem with the VS web server and IE7. It works ok in Firefox
using the local server. I get this message in IE when clicking the link with
the querystring.

"Internet Explorer cannot download Download.aspx from localhost. Internet
Explorer was not able to open this internet site. The requested site is
either unavailable or cannot be found. Please try again later."

I've tested it using an IIS web server and it works ok. The only problem for
me is that it opens a blank window as well as a file download pop up window.
Do you know if I can stop the new window displaying?

Thanks again
Andrew
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:d9**************@TK2MSFTNGHUB02.phx.gbl...
Hi Andrew,

The window.open function can open a URL with querystring; your code looks
fine, I'm not sure what's the issue you're having?

To add a javascript function in the page, you can use
ClientScript.RegisterClientScriptBlock or
ClientScript.RegisterClientScriptBlock.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.


Jun 7 '07 #6

P: n/a
Hi Andrew,

Please try following two WebForm:

Default2.aspx:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
Link1.Command += new CommandEventHandler(Link1_Command);
}

void Link1_Command(object sender, CommandEventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "download",
"window.open('Download2.aspx?id=123', '_blank')", true);
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="Link1" runat="server"
Text="Download"></asp:LinkButton>
</div>
</form>
</body>
</html>
Download2.aspx:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"];
DownloadFile(new System.IO.FileInfo(@"c:\1.bin"));
}

void DownloadFile(System.IO.FileInfo fi)
{
Response.AddHeader("Content-Disposition", "attachment; filename=" +
fi.Name);
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(fi.FullName);
Response.End();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

In Download2.aspx, you should be able to get the querystring id and use
this to download different file.

Also, I didn't see the empty window left open when the file is downloaded
on IE7.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 8 '07 #7

P: n/a
Hi Andrew,

I'm wondering if you have tried the code in my last reply. Please feel free
to let me know if there's anything else I can help.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 13 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.