I have added one custom property in my SharePoint 2010 site, which gives me a TextBox to fill values.

My requirement is I want one Text with HyperLink on it.

How can I add HyperLink Property to my Visual Web Part??

It should looks like below:


  • The link in your question just goes to our home page. Do you mean a textbox in the web part edit panel, or in the rendered content of the web part?
    – SPDoctor
    Nov 16, 2011 at 13:09
  • The rendered content of the web part. I want a HyperLinked Text which will contain the URL to an existing List.
    – NICK
    Nov 16, 2011 at 13:16

2 Answers 2


I think maybe the easiest way to do this is to provide two separate fields, one for the link's display text and another for the link itself, and to dynamically build the link you need in the Visual Web Part's code behind.

  • Could you please describe How I will achieve this??
    – NICK
    Nov 16, 2011 at 13:17

Out-of-box , a custom property is rendered in the "Modify Web Part" pane based on its type as :

  • String, DateTime or Int type is rendered as TextBox

  • bool type is rendered as CheckBox

  • enum type is rendered as Dropdown

So, if you want to see a control in the property pane to enter a url (like SharePoint Url field), you have to develop a custom EditorPart for that Webpart.

If you just want to render it as hyperlink in webpart, you can use two string properties for text and href and build the link in code to render. For e.g :

  //property attributes removed for simplicity
    public string UrlText{ get;set;}
    public string UrlHref{ get;set;}

    protected override void Render(HtmlTextWriter writer)
        writer.Write("<a href'" + UrlHref + "'>" + UrlText + "</a>"); 
  • I'm at beginner to intermediate level still, can someone please help me with some code sample??
    – NICK
    Nov 16, 2011 at 13:26
  • see added sample above Nov 16, 2011 at 13:41
  • Thanks for the code, should I add this code into my VisualWebPart1.cs file??
    – NICK
    Nov 16, 2011 at 13:50
  • Hi, I think I have confused you with my requirements. My requirements is I want to see a control in the property pane but not to enter URL, just to show URL.
    – NICK
    Nov 16, 2011 at 13:52
  • 1
    Then use a literal control to place <a> in a custom EditorPart. To develop editorpart see here :wictorwilen.se/Post/… Nov 16, 2011 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.