473,538 Members | 4,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reload calling page in ASP.NET 2.0

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
7 29632
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2357
by: Ike | last post by:
Suppose I have a frame like 123bottom.html and within it, I want to promt the user for a response (in the <HEAD>) like var ans = prompt("What is your name?"); and then reload the page (via, say window.location.reload() ?) using the argument of the value of ans appended onto the url so that, in effect, say, I am calling the new frame as
1
2059
by: Marshall Dudley | last post by:
I need to be able to allow a user to submit a form which opens another window. This part I have working. But after the submit, I need to delay and have the original window do a reload. I cannot figure out how to do this. If I do a delay and reload with an OnSubmit, then the new window will load only after the reload, which will not work. ...
1
1888
by: Iver Erling Årva | last post by:
Hi! I wonder if anyone knows how to do this. I use layers in one of my html pages to simulate tabs like tabs in windows application. I have one layer per "page/tab" and call them Layer1,Layer2,Layer3 etc. and use a visible/invisible style setting to display the right one according to that tab the user clicks. On one of the layers the user...
2
3281
by: Christian Ista | last post by:
Hello, I explain the situation, I have 3 pages A, B and C. On the page A, I display some data, on this page there is an edit button. When I push on the edit button, I call the page B, on this page, a form with the data to edit. When I submit the form I call the page C to update the data in the database.
19
31007
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). The problem is that after the reload, it brings you right to the top of the page. When I click 'refresh" on the original page, it brings me back to...
8
3366
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some problems. IE crashes when one refreshes the page or leave the page. This happens only after calling the Java method more than once. It does not crash if...
12
3103
by: joe | last post by:
I have a Javascript page which needs to be dynamically changed depending on user input. The whole page is written on document.write() output. I am still new to Javascript and run into problems with page reload. When user presses a button on my page most functions should clear the page and repaint it using my wholepage() function. After a...
8
6734
by: T. Wintershoven | last post by:
Hi all, Is there a simple way in php to reload a page coded within an if statement.(see code below) It's very important that the session stays intact. The filename is RCStudent.php **************** A peace of code*************************** <?php session_start();
0
7365
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7694
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4852
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3353
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
933
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.