0

I'm trying to dynamically change the title of a SharePoint page via a web part on the page, but using Page.Title = "New Title" in my control yields no results, assuming that somewhere down the line SharePoint overrides my changes with default page title values.

Is this possible?

Basically, I have a component on the page with links. Clicking on any of these links will reload the current page with relevant data. The link clicked on should denote the page's title. I can achieve this with JavaScript once the page has finished loading, but would like to try a coding solution first.

  • 1
    I think you want to be using an SPFile object that's linked to the page in the pages document library to change things in SP. Page is the base ASP.NET class so many things don't work as you might expect. – TZHX Aug 13 '12 at 11:02
2

If you are looking to change the page title of a custom page, please try below

SPListItem item = SPContext.Current.ListItem;

if (item != null)
{
    item[SPBuiltInFieldId.Title] = <newTitle>;
    item.SystemUpdate(false); // this will make sure modified or modifiedby field is not updated
}

If you are trying to do by replacing the contentplaceholder, please check this,

http://blogs.perficient.com/microsoft/2007/08/programmatically-setting-a-web-part-pages-title/

1

Add in a content editor web part into your Web Part Page, edit the HTML source and add the below javascript.

<script type="text/javascript"> document.title = "Your Title Goes Here"; </script>

  • have a JS solution, just wanted to do it via code as stated above. thanks. – JadedEric Aug 13 '12 at 11:14

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.