asp.net LinkButton超链接问题
我的页面上有以下两个控件:
<asp:LinkButton ID="OpenLB" runat="server" >Open</asp:LinkButton>
<asp:HyperLink ID="OpenHL" runat="server">Open</asp:HyperLink>
我在页面加载期间设置它们,如下所示:
OpenLB.PostBackUrl = @"file:\\web\documents-emails\doc1.docx";
OpenHL.NavigateUrl = @"file:\\web\documents-emails\doc1.docx";
OpenHL 工作,它打开 word 文件。
OpenLB 不起作用,当我点击它时,我收到一个错误弹出窗口,显示:
Windows Internet Explorer 找不到 文件 '文件://web //documents-emails //doc1.docx'。 确保路径或 Internet 地址 是正确的。
好像网址不一样或者什么的,我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
LinkButton 的工作原理是使用给定的 url 将网页发布回服务器。它以超链接的样式显示按钮,但使用 javascript 将表单发送回给定 url 处的服务器。您将无法将其与
file:
url 一起使用,因为您无法 POST 到本地文件。超链接只是创建一个锚点,当单击该锚点时,浏览器的位置将被设置为 url。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.HyperLink
旨在链接到另一个页面或文件。它只是标记的包装器。
LinkButton
旨在回发页面并在服务器端触发事件。首先确保您在每种情况下都使用正确类型的控件。
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.
我认为这很简单,在一种情况下,您正在导航到该文件,并且它会按预期打开,而在另一种情况下,您要求它发布到 docx 文件,而它应该是一个有效的 URL
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
链接按钮的默认行为是回发到 aspx 页面以处理回发事件,以响应最终用户单击链接。默认情况下,postbackurl 为空,表示链接回发到当前页面。设置 postbackurl 属性旨在用于跨页面回发,在这种情况下,您将处理另一个 apsx 页面上的单击事件。
MSDN Postbackurl 属性
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