0

I have a label created dynamically that displays content and a local link to files so that these can be downloaded or viewed in a browser.

label.Text="..content.." + " <asp:HyperLink runat=\"server\" NavigateUrl=\"~/c/customer/uploads/TestDocument.docx\">HyperLink</asp:HyperLink>";

I can use a hyperlink control or an <a> tag to display the link in the dynamic label and I can see the link address is basically correct except that Visual Web Developer 2010 Express automatically adds the root path as a prefix

http://localhost:50969/website/

to the path string followed by the URL I added enclosed inside 2 single quote quotation marks.

http://localhost:50969/website/'c/customer/uploads/TestDocument.docx'

When I click the link, the page throws resource cannot be found error. I think that the 2 single quotes are causing the error. Is there a way to remove the single quotes? Or is there a better technique to this?

matt2605
  • 216
  • 1
  • 3
  • 18
  • Could you try `NavigateUrl='~/c/customer/uploads/TestDocument.docx'` instead of `NavigateUrl=\"~/c/customer/uploads/TestDocument.docx\"`? Reference: [Server tag not parsed in asp:Hyperlink](http://stackoverflow.com/a/14130823/6741868) – Keyur PATEL Feb 09 '17 at 01:27
  • @KeyurPATEL This is the resulting url http://localhost:50969/website/'c/customer/uploads/TestDocument.docx' which is the same and the same error but technically incorrect syntax because the double quote signs the end of the linkbutton start tag. – matt2605 Feb 09 '17 at 04:44
  • @KeyurPATEL There is logic in your suggestion. With manipulation the single quotes are removed. I will keep the post updated. – matt2605 Feb 09 '17 at 05:54

1 Answers1

1

You are trying to add a asp.net Control as a string to a Label, but that will never work.

Either use the HyperLink control correctly by placing it on the aspx page and set the NavigateUrl property.

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/c/customer/uploads/TestDocument.docx">HyperLink</asp:HyperLink>

Or create a "normal" hyperlink as a string.

label.Text = "..content..<a href=\"~/c/customer/uploads/TestDocument.docx\">HyperLink</a>";
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • If you read the question properly, you'll see that the control or the link can't be put on the aspx page because it must added dynamically or as a string. – matt2605 Feb 09 '17 at 20:21