Deane Barker
Sep 2, 2010
(1 votes)

Automatically Naming Pages

Here’s a fact -- not every page needs to be explicitly named.  I mean, they all have to have names, but you shouldn’t have to manually enter them all the time.

Often, a page should have its name derived from other properties.  For instance, if you have a page representing a person, you’re probably going to have separate fields for FirstName and LastName.  By logical extension then, the page name should be something like “FirstName LastName,” or “LastName, FirstName.”  You don’t want the editor to have to enter three things – the first name, the last name, and the page name…which is the first name and the last name all over again.

Now, you can set page names from code.  Just catch the PageCreating or PageSaving event, and set the value of e.Page.PageName, no problem.  But this is less than ideal because the pesky “Name” field is still in Edit Mode just begging for some input.  This looks tacky (“Yeah, you have to put something in there…but we’re not going to use it…so, it doesn’t really matter…”), and it’s potentially confusing for editors (“I entered X there, and now its set to Y…”).

So, how do you get rid of it?  I asked this question in the forums, and Linus showed me how it’s done.

The EditPanel object throws an event, which you can hook to modify the page that’s loading into it.  What you do is just change the DisplayEditUi boolean on the Pagename property.  You can do this in Application_Start, like this:

protected void Application_Start(Object sender, EventArgs e)
    EPiServer.UI.Edit.EditPanel.LoadedPage += new EPiServer.UI.Edit.LoadedPageEventHandler(EditPanel_LoadedPage);
private void EditPanel_LoadedPage(EPiServer.UI.Edit.EditPanel sender, EPiServer.UI.Edit.LoadedPageEventArgs e)
    e.Page.Property["Pagename"].DisplayEditUI = false;

This works great, but since I had 3-4 page types that needed to be handled, I built it out a little further.  I link to a class file below that you’re welcome to use.  In it, you have a List of PageTypeNames that should have their name field suppressed, like this:

private static List<string> affectedPageTypes = new List<string>() { "Council Member", "Periodical" };

Additionally, there’s a switch statement lower down where you can put the logic to derive your page names based on type:

// Modify the code below to custom-name your pages
switch (e.Page.PageTypeName)
    case "Council Member":
        // Example: "Barker, Deane"
        pageName = String.Format(
            "{0}, {1}",

    case "Periodical":
        // Example: "2010: Vol. 32, No. 2"
        pageName = String.Format(
            "{0}: Vol. {1}, No. {2}",

It’s a single class file.  Change the code as-needed, and compile it into your project.  (Normal warnings apply –  I wrote this about an hour ago, and it’s only been tested for about five minutes…)

Sep 02, 2010


Sep 21, 2010 10:33 AM

Nice one - and elegant solution

Sep 21, 2010 10:33 AM

Very nice!

May 18, 2015 03:04 PM

Is there any way to get a version of this for newbies to EpiServer?

Please login to comment.
Latest blogs
Implementing EmbeddedLocalization in Optimizely CMS 12

My previous post on translation (Translating Optimizely CMS 12 UI components) gives an overview of how to implement the FileXmlLocalizationProvider...

Eric Herlitz | Jan 27, 2023 | Syndicated blog

Breaking changes in EPiServer.CMS.TinyMce 4.0.0

After upgrading to the latest version of EPiServer.CMS.TinyMce, the dropdown with formats disappears. Learn how to get it back!

Tomas Hensrud Gulla | Jan 27, 2023 | Syndicated blog

Translating Optimizely CMS 12 UI components

Optimizely CMS 12 have been out for a while now, but still some elements haven't been properly translated resulting in a GUI defaulting to english....

Eric Herlitz | Jan 26, 2023 | Syndicated blog

Image preview in Optimizely CMS12 all properties view

With these simple steps, you can now see an Image and its Metadata, including size and dimensions, when editing an Image property in Optimizely...

Tomas Hensrud Gulla | Jan 26, 2023 | Syndicated blog