简体   繁体   English

具有超链接的ASP.NET页面标记

[英]ASP.NET Page Markup with Hyperlink

I have a question regarding the page markup of a hyperlink. 我对超链接的页面标记有疑问。 I have a form view on an aspx page which has a datatable bound to it in the code behind. 我在aspx页面上有一个表单视图,在后面的代码中有一个绑定到它的数据表。 I have some controls on the aspx page that get data bound to them in the markup. 我在aspx页面上有一些控件,这些控件在标记中获取绑定到它们的数据。 I have a hyperlink control that needs one field bound to it in the text property (which I figured out) and one field bound to it in the hyperlink propoerty (which I need help with). 我有一个超链接控件,需要在text属性中绑定一个字段(我已经弄清楚了),并且在超链接属性中需要绑定一个字段(我需要帮助)。 I got the page to somewhat accept the markup, but when the link it clicked the link is somehow broken. 我让页面在某种程度上接受了标记,但是单击链接时,链接以某种方式损坏。

Also, can I not use the navigate URL property to navigate to an outside URL? 另外,我不能使用Navigation URL属性导航到外部URL吗? Say, WWW.ESPN.COM? 说,WWW.ESPN.COM? I think that is the problem... 我认为这是问题所在...

<asp:HyperLink runat="server" ID="lnkCustom" NavigateUrl='<%#DataBinder.Eval(Container.DataItem, "WebCustomHyper")%>' Target="_blank" CssClass="weblinks">
                                <%# DataBinder.Eval(Container.DataItem, "WebCustomHyperDesc")%></asp:HyperLink>

Any Ideas? 有任何想法吗?

Also, can I not use the navigate URL property to navigate to an outside URL? 另外,我不能使用Navigation URL属性导航到外部URL吗? Say, WWW.ESPN.COM? 说,WWW.ESPN.COM? I think that is the problem... 我认为这是问题所在...

Indeed that may very well be the problem. 确实,这很可能就是问题所在。 It depends on what the rendered client-side markup looks like. 这取决于呈现的客户端标记的外观。 Let's say, for the sake of argument, that the page is at http://www.example.com/page.aspx . 出于争论的原因,假设该页面位于http://www.example.com/page.aspx Then if the link looks like this: 然后,如果链接看起来像这样:

<a href="www.espn.com">click here</a>

Clicking it will try to take the user to: 单击它会尝试使用户执行以下操作:

http://www.example.com/www.espn.com

Which, of course, won't work. 当然,这是行不通的。 This is because the value www.espn.com alone doesn't tell the browser that it should be going to a different location. 这是因为仅www.espn.com这个值并不能告诉浏览器应该将其转到其他位置。 It's entirely possible that you have a file on the server called www.espn.com as far as the browser is concerned. 就浏览器而言,很有可能在服务器上有一个名为www.espn.com的文件。

In order to direct it properly, you need to fully-qualify the URL. 为了正确定向,您需要完全限定URL。 Which basically means you need to prepend the protocol prefix. 这基本上意味着您需要在协议前缀之前添加。 Something more like this: 像这样:

<a href="http://www.espn.com">click here</a>

This would fix the link and direct the user to the correct destination. 这将修复链接并将用户定向到正确的目的地。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM