1

I want to change the title of the web part in the runtime. I have a scenario where I need to display the username on the title of the webpart. eg: the web part title as "Welcome Ram"

  • Nice to hear! What technologies are you allowed to use, is this on one page or many? – Robert Lindgren Mar 14 '14 at 12:20
  • It is a global web part in my farm solution and I am using SharePoint 2010 on premises. I want to welcome user with in the web part title and display his personal links in the web part. – Ram Mar 14 '14 at 12:23
5

You can add a simple label inside of your web part like:

<asp:Label runat="server" ID="LabelWelcome"></asp:Label>

And in the page load method in code behind set the text of that label like:

this.LabelWelcome.Text = "Welcome " + SPContext.Current.Web.CurrentUser.Name;

Then just set Chrome Type property to None in web part settings, so web part won't show it's real title :)

  • 1
    I agree with Gintas K. Showing a welcome message in the webpart is better than changing the title of the webpart on every page load. How you want to display that welcome is up to you, but Gintas example works just fine. =) – Johannes Mar 17 '14 at 13:30
  • I agree with the above posters. – Cameron Verhelst Mar 17 '14 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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