+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Making the newly added Website field a URL

Making the newly added Website field a URL

4 posts, 0 answered
  1. Andre
    Andre avatar
    10 posts
    Registered:
    29 Dec 2011
    03 Feb 2012
    Link to this post
    Hi,

    For the events, I added a new field called, Web site. This field contains a URL to an external Website. I got it to show up as text by following tutorials and examples available on this form.

    However, I do not know how to turn this field into a <a href type of a field. This is what I have now in the control template:
    <li><b>Web Site: </b><asp:Literal ID="WebSite" runat="server" /></li>

    I tried a few things but no luck. Please help.

    Thank you,
    Andre
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    02 Dec 2016
    06 Feb 2012
    Link to this post
    Hi Andre,

    Can you please share with us the control template, or let us know if there's any specific reason why you won't surround the custom field in <a href> tag so  the rendered output of your custom field will then be displayed as hyperlink?  Generally one option would be to use Eval in your markup to get the value of your field, the other to declare an asp:HyperLink control int eh markup and set the NavigateUrl property in the code-behind where you can operate with the custom field. Please do not hesitate to get back to us if you need some additional information or have further questions.

    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Andre
    Andre avatar
    10 posts
    Registered:
    29 Dec 2011
    07 Feb 2012
    Link to this post
    Could you please show me an example of how I would turn this into a link?

    I tried <a href="<asp:Literal ID="WebSite" runat="server" />"><asp:Literal ID="WebSite" runat="server" /></a>

    But that doesn't work and I'm sure that is not the proper way to do it. Pretty much WebSite field has both the URL and the text that will be linked. So it should be like  <a href=WebSite>WebSite</a>  format.

    Thank you
  4. Andre
    Andre avatar
    10 posts
    Registered:
    29 Dec 2011
    09 Feb 2012
    Link to this post
    By the way, I figured it out. I will post it here and maybe it will help someone :-)
    I just included this code in the control template.


    <SCRIPT Runat="Server">

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WebSite.Text = "<a href='" + WebSite.Text + "'>" + WebSite.Text + "</a>";
        }
    }
       
    </SCRIPT>
Register for webinar
4 posts, 0 answered