Use Hyperlink or LinkButton controls on a page to download documents from server?

Hi, I need to provide a page with links to download files from the server.  However, I am not sure what would be an ideal control to use for this scenario?  Would it be Hyperlink or LinkButton?  
The names of the files are never the same.  Upon clicking on the links, the code needs to get the server path from the web.config file and the filename would have to be built based on the ID of the case selected.  It is also important that the link is reusable to download the file again without having to refresh the page.

I truely appreciate your time and assistance on this.
Thank you so much!
LISCNYAsked:
Who is Participating?
 
McExpConnect With a Mentor Commented:
During the PageLoad event (of your page) you need to set the NavigateUrl of a Hyperlink control, see below for an example: -

--In your page--
<asp:HyperLink runat="server" ID="hlTheLink" Text="Open Document" />

--In your Page Load Event of the Code Behind--
string theUrl = BuildUrlFromWebConfigAndCase(CaseId);
hlTheLink.NavigateUrl = theUrl;

--Write a function to compise the URL you need--
private string BuildUrlFromWebConfigAndCase(int CaseId)
{
//Some Code
}
0
 
McExpCommented:
Do you need to open in the same window or a new window?
0
 
LISCNYAuthor Commented:
The download dialog box should pop up when links are clicked on the page.  The users typically save the files on their local drive, but if they open the file from the dialog, it would open on a new document window.  However, the user should be able to close the opened document window and see the page with links.

Thanks for your time!
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
McExpCommented:
Then you need a hyperlink control.
0
 
LISCNYAuthor Commented:
Thank you.  Would you be able to refer me to a sample code?
0
 
LISCNYAuthor Commented:
My boss just told me to do this using LinkButtons so I was able to get the desired result using LinkButtons.  Thank you for all your assistance.
0
 
McExpCommented:
The only issue with the LinkButton alternative is that it requires an aditional postback to your web server to then redirect to the actual file. Whereas the Hyperlink will load the file directly.

The Hyperlink based solution is the marginally better (faster) solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.