Open

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?

+4
source share
4 answers

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.

+6
source

A HyperLink designed to link to another page or file. This is just a wrapper for the <a> tag.

A LinkButton designed to publish a page and trigger an event on the server side.

First make sure that you use the right type of control in every situation.

+2
source

I think it’s just that in one case you go to the file and it opens, as expected, the other one that you request post in the docx file when it should be a valid URL

0
source

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.

Postbackurl Property for MSDN

0
source

Source: https://habr.com/ru/post/1303286/


All Articles