views:

423

answers:

4

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?

A: 

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

curtisk
+4  A: 

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.

tvanfosson
Agreed. The point of the PostBackUrl is to allow your form to post back to another URL rather than the default action of posting back to the page itself.
smencer
A: 

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

Athens
A: 

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.

Jon Seigel