Try our conversational search powered by Generative AI!

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
Optimizely Web... 6 Game Changing Features in 2024

If you are interested in learning about what's new within Optimizely Web, you are in the right place. Carry on reading to learn about the 6 greates...

Jon Jones | Mar 3, 2024 | Syndicated blog

Headless forms reloaded (beta)

Forms is used on the vast majority of CMS installations. But using Forms in a headless setup is a bit of pain since the rendering pipeline is based...

MartinOttosen | Mar 1, 2024

Uploading blobs to Optimizely DXP via PowerShell

We had a client moving from an On-Prem v11 Optimizely instance to DXP v12 and we had a lot of blobs (over 40 GB) needing uploading to DXP as a part...

Nick Hamlin | Mar 1, 2024 | Syndicated blog

DbLocalizationProvider v8.0 Released

I’m pleased to announce that Localization Provider v8.0 is finally out.

valdis | Feb 28, 2024 | Syndicated blog