Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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:

StackExchange

share|improve this question
    
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 '11 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 '11 at 13:16
add comment

2 Answers

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.

share|improve this answer
    
Could you please describe How I will achieve this?? –  NICK Nov 16 '11 at 13:17
add comment

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>"); 
    }
share|improve this answer
    
I'm at beginner to intermediate level still, can someone please help me with some code sample?? –  NICK Nov 16 '11 at 13:26
    
see added sample above –  Amit Kumawat Nov 16 '11 at 13:41
    
Thanks for the code, should I add this code into my VisualWebPart1.cs file?? –  NICK Nov 16 '11 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 '11 at 13:52
1  
Then use a literal control to place <a> in a custom EditorPart. To develop editorpart see here :wictorwilen.se/Post/… –  Amit Kumawat Nov 16 '11 at 14:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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