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:
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI 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:
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.
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>");
}