locked
hyperlink eval navigateurl complete path not required RRS feed

  • Question

  • User-1513812710 posted

    In database I have a column for website name. This website I am displaying inside a listview in a hyperlink field. I want that when user click on the link it should redirect to the website in new tab but right now when clicking the folder structure is prefixing before the website name. Here is the code for Hyperlink. What should I do to remove the prefix from website name. The text of website is displaying fine. Please advice:

    <asp:HyperLink ID="hplWebsite" runat="server" style="text-decoration: underline;" Text='<%# Eval("Website")%>' NavigateUrl='<%# Eval("Website")%>' Target="_blank"></asp:HyperLink>

    Monday, June 1, 2020 11:52 AM

Answers

  • User409696431 posted

    You have to include the full website address = "https://www.name.com".   I assume you are not doing that.  Either that must be in the database, or you must prepend https:// or http:// in the NavigateURL. However, you may have problems trying to prepend it the NavigateUrl because you wouldn't have a way of knowing if it is https:// or http://, so it's best if you put the entire address in the database and parse it to remove the http// or https// for the Text value..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 1, 2020 3:46 PM

All replies

  • User409696431 posted

    You have to include the full website address = "https://www.name.com".   I assume you are not doing that.  Either that must be in the database, or you must prepend https:// or http:// in the NavigateURL. However, you may have problems trying to prepend it the NavigateUrl because you wouldn't have a way of knowing if it is https:// or http://, so it's best if you put the entire address in the database and parse it to remove the http// or https// for the Text value..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 1, 2020 3:46 PM
  • User288213138 posted

    Hi anuragacc123,

    In database I have a column for website name. This website I am displaying inside a listview in a hyperlink field. I want that when user click on the link it should redirect to the website in new tab but right now when clicking the folder structure is prefixing before the website name. Here is the code for Hyperlink. What should I do to remove the prefix from website name. The text of website is displaying fine.

    Do you want to remove the website prefix from Text? if so, you can try below code:

    <asp:HyperLink ID="hplWebsite" runat="server" style="text-decoration: underline;" 
    Text='<%# Eval("Website").ToString().Replace("https://","")%>' NavigateUrl='<%# Eval("Website")%>' Target="_blank"></asp:HyperLink>

    The result:

    Best regards,

    Sam

    Tuesday, June 2, 2020 2:34 AM
  • User-2054057000 posted

    You can call a C# function for this:

    <asp:HyperLink ID="hplWebsite" runat="server" style="text-decoration: underline;" Text='<%# Eval("Website")%>' NavigateUrl='someFunction()' Target="_blank"></asp:HyperLink>

    Inside the C# function you return your website url.

    Tuesday, June 2, 2020 3:06 PM