Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > Making the newly added Website field a URL

Making the newly added Website field a URL

  • Andre avatar

    Posted on Feb 3, 2012 (permalink)

    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

    Reply

  • Boyan Barnev Boyan Barnev admin's avatar

    Posted on Feb 6, 2012 (permalink)

    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

    Reply

  • Andre avatar

    Posted on Feb 7, 2012 (permalink)

    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

    Reply

  • Andre avatar

    Posted on Feb 9, 2012 (permalink)

    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>

    Reply

  • Register for webinar
Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): Developing with Sitefinity > Making the newly added Website field a URL