The idea of http://blog.163.com/red_guitar@126/blog/static/117206128201123845276/, put a shadow iframe in the modal window page.
First, we create a new modal window in the modal window a. aspx Java code
- <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <Html xmlns = "http://www.w3.org/1999/xhtml">
- <Head runat = "server">
- <Base target = "_ self"/>
- <Title> </title>
- </Head>
- <Body>
- <Form id = "form1" runat = "server">
- <Center>
- <Asp: LinkButton ID = "ibDownLoad" runat = "server" onclick = "ibDownLoad_Click"> click here to download the file </asp: LinkButton>
- </Center>
- <Iframe id = "download" runat = "server" style = "display: none;"> </iframe>
- </Form>
- </Body>
- </Html>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Background code: Java code
- Protected VoidIbDownLoad_Click (object sender, EventArgs e)
- {
- String filePath = Server. MapPath ("\ PDF \ a.txt ");
- Download. Attributes ["src"] = "DownLoad. aspx? FilePath = "+ filePath;
- }
protected void ibDownLoad_Click(object sender, EventArgs e) { string filePath = Server.MapPath("\\PDF\\a.txt"); download.Attributes["src"] = "DownLoad.aspx?filePath=" + filePath; }
Process DownLoad. aspx on the file DownLoad page. The page code is not written and written in the background code: Java code
- Protected VoidPage_Load (object sender, EventArgs e)
- {
- String filePath = Request. QueryString ["filePath"];
- // String filePath = Server. MapPath ("\ PDF \ a.txt ");
- If(File. Exists (filePath ))
- {
- FileInfo file =NewFileInfo (filePath );
- Response. ContentEncoding = System. Text. Encoding. GetEncoding ("UTF-8"); // solve Chinese garbled characters
- Response. AddHeader ("Content-Disposition", "attachment; filename =" + Server. UrlEncode (file. Name); // fix Chinese file Name garbled characters
- // Response. AddHeader ("Content-Disposition", "attachment; filename =" + file. Name );
- Response. AddHeader ("Content-length", file. Length. ToString ());
- Response. ContentType = "appliction/octet-stream ";
- Response. WriteFile (file. FullName );
- Response. End ();
- }
- }
Protected void Page_Load (object sender, EventArgs e) {string filePath = Request. queryString ["filePath"]; // string filePath = Server. mapPath ("\ PDF \ a.txt"); if (File. exists (filePath) {FileInfo file = new FileInfo (filePath); Response. contentEncoding = System. text. encoding. getEncoding ("UTF-8"); // solves Chinese garbled Response. addHeader ("Content-Disposition", "attachment; filename =" + Server. urlEncode (file. name); // solves Chinese file Name garbled characters // Response. addHeader ("Content-Disposition", "attachment; filename =" + file. name); Response. addHeader ("Content-length", file. length. toString (); Response. contentType = "appliction/octet-stream"; Response. writeFile (file. fullName); Response. end ();}}
OK. This will solve some problems such as clicking the download link in the modal window, or the pop-up prompt. From: http://269181927.javaeye.com/blog/865034