I am working on a internet site which has all the best practices used in it. I have a simple task but want to make sure that i also use the best possible solution.

The requirement is that i have to output a text which contains a link on the webpart

so i have taken a literal

<asp:Literal ID="litVal" runat="server"></asp:Literal>

and in code behind string outVal = someFunction();//get val from list

value of outVal is (without quotes)

"some text here some text, some text here some text here"

Now, what i have to do is - to get the link on the part of the text after "comma"

1 Answer 1


Not sure I'm clear on what the issue is but why are you not using HyperLink control instead? Within the code behind or in the ASCX code, you can set the value of the control easily.

Be aware of how the Visual Web Parts actually work:

1) The Web Part - this hosts the control and is how you can create web properties to pass to the control (this provides the SharePoint context to the control).

2) The Control - separate code behind but is effectively a .NET control running 'on top' of SharePoint. By default, it doesn't even have a reference to SP (this has to be added). However, the context is there so you can access SharePoint in the background.

Coding a Visual Control is the same as .NET; all the same controls are available. If you get it to work in a .NET site, you can cut/paste into a Visual Control.

David Sterling davidmsterling.blogspot.com www.sterling-consulting.com

  • 1
    and to be complete (I don't understand the question either ;) ): To just get the string behind the comma, use outVal.Split(',').Last() in your code-behind.
    – Dominik
    Dec 14, 2012 at 19:11

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.