简体   繁体   中英

Unable to see Redirect page name

I have a page which has a LinkButton,my requirement is when i click on 'DownLoad; Linkbutton the page should redirect to another page and there my file should be download and my web page address bar should display that which page it is redirecting also my querystring value. please suggest me how would I do that please help me.

here is my code

FirstPage.aspx

 protected void LinkButton1_Click(object sender, EventArgs e)
    {

        Response.Redirect("Default2.aspx?filename=Csharp/CSharp.txt");              
    } 


Download.aspx

 protected void Page_Load(object sender, EventArgs e) <br/>

    {
        string filename = Request.QueryString["filename"];
        Response.ContentType = "text";
        Response.AppendHeader("Content-Disposition", "attachment; filename=CSharp.txt");
        Response.TransmitFile(Server.MapPath(filename));
        Response.End(); 
    }

I used this code in each and every event of Download.aspx page event but i couldn't. note:I have this requirement exactly that i have to use querystring and also the redirected page and querystring value should show in the address bar before download.

Use additional flag to indicate that the the actual downloading should be made. In a meantime you can show a "Please wait" message. Like this:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="refresh" content="3; url=<%=HttpUtility.HtmlAttributeEncode(Request.Url.OriginalString + &IsDownloading=true")%>">
  </head>

  <body>
    <h2>Your download will start shortly...</h2>
  </body>
</html>

Code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    if(string.Compare((Request.QueryString["IsDownloading"] ?? string.Empty).Split(new char[] { ',' }).First(), "true", StringComparison.InvariantCultureIgnoreCase) == 0)
  {
    // Make a file transfer
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM