Problem with asp.net LinkButton HyperLink
The following two controls on my page:
<asp:LinkButton ID="OpenLB" runat="server" >Open</asp:LinkButton> <asp:HyperLink ID="OpenHL" runat="server">Open</asp:HyperLink> I installed them during page load as follows:
OpenLB.PostBackUrl = @"file:\\web\documents-emails\doc1.docx"; OpenHL.NavigateUrl = @"file:\\web\documents-emails\doc1.docx"; OpenHL works, it opens a word file.
OpenLB does not work, when I click on it, a popup window appears with an error saying:
Windows Internet Explorer Cannot find the file 'File: //web//documents-emails//doc1.docx. Make sure the path or internet address is correct.
It looks like the url is different or something else, how can I fix this?
LinkButton works by publishing a web page to a server using a given URL. It displays a hyperlink-style button, but uses javascript to send the form back to the server at the specified URL. You cannot use it with the file: URL, since you cannot send POST to a local file. HyperLink simply creates a binding, which causes the browser location to be set to the URL when it is clicked.
The default behavior of the link button is to send back to the aspx page to handle the post back event in response to the end user by clicking the link. By default, postbackurl is empty by default, indicating that links link to the current page. Setting the postbackurl property is intended for backlinks on the page, in which case you will handle the click event on another apsx page.