asp.net - Download File link on ascx without popup -


i have link on ascx, want have file download prompt without doing popup.

example:

  <a href="download.aspx">download</a> 

then in download.aspx page_load have:

    dim dataas string = "test"      response.clear()     response.addheader("content-disposition", "attachment; filename=" & "test.dat")     response.addheader("content-length", achdata.length.tostring())     response.contenttype = "text/plain"     response.write(data)     response.end() 

is right way? other way putting code in post of ascx

<asp:button text="download" id="thebutton" /> 

.vb

public sub thebutton_click()     response.clear()     response.addheader("content-disposition", "attachment; filename=" & "test.dat")     response.addheader("content-length", achdata.length.tostring())     response.contenttype = "text/plain"     response.write(data)     response.end()  end sub 

the content disposition can either attachment or inline, e.g.:

response.addheader("content-disposition", "inline") 

if make attachment, browser typically display popup asking user whether open file or save it. browser in control of happens after return http response. default filename may 1 suggest, or browser may decide ignore filename altogether , maybe use ascx filename (firefox listed bug when ran it, ie seemed consider "feature").

but if make inline, "text/plain" content type dumped browser screen without popup. want?


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -