Enriquev
Enriquev

Reputation: 929

asp.net LinkButton HyperLink problem

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 set them during page load like this:

OpenLB.PostBackUrl = @"file:\\web\documents-emails\doc1.docx";
OpenHL.NavigateUrl = @"file:\\web\documents-emails\doc1.docx";

OpenHL works, it opens the word file.

OpenLB doesnt work, when I click on it, I get a error pop-up that says:

Windows Internet Explorer Cannot find 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, how can I fix this?

Upvotes: 4

Views: 7778

Answers (4)

Jon Seigel
Jon Seigel

Reputation: 12401

A HyperLink is designed to link to another page or file. It's simply a wrapper for an <a> tag.

A LinkButton is designed to post back the page and fire an event on the server side.

First make sure you're using the correct type of control in each situation.

Upvotes: 2

Athens Holloway
Athens Holloway

Reputation: 2203

The default behaviour of the linkbutton is to post back to an aspx page to handle the post back event in response to the end user clicking the link. The postbackurl is blank by default indicating the the link posts back to the current page. Setting the postbackurl property is intended for cross page postbacks in which case you will handle the click event on another apsx page.

MSDN Postbackurl Property

Upvotes: 0

tvanfosson
tvanfosson

Reputation: 532445

The LinkButton works by posting the web page back to the server using the given url. It displays the button in the style of a hyperlink, but uses javascript to post the form back to the server at the given url. You won't be able to use it with a file: url since you can't POST to a local file. The HyperLink just creates an anchor which results in the location of the browser being set to the url when it is clicked.

Upvotes: 6

curtisk
curtisk

Reputation: 20175

I think its simply that in one case you are navigating to the file, and it opens as expected the other you are asking it to post to the docx file, when it should be a valid URL

Upvotes: 0

Related Questions