Tag Archives: prepopulate

Prepopulate fields when creating page

Made a joblisting about a month ago, the site I made it for is a globalized site with three different languages (so far). Every work ad needs a start- and a stop-publish date, and the work ad is first created in one language, then translated by some other to other languages.

When I checked around the site a week ago i noticed that the joblisting had different sorting depending on what language I had choosen. So I started my research and noticed that the start- and stop publish was only set in the master language, and the other pages had a different start publish and no stop publish… Of course, you need to set publish dates on all languages. This was not an option..

Then I remembered that you can prepopulate data in the edit-fileds, but how? Started thinking again.. global.asax.. events.. hmm.. advanced developing with episerver, that’s right. Found my course material and checked a random page in it, and there it was! So this is how I solved it:

In Global.asax

protected void Application_Start(Object sender, EventArgs e)
{
DataFactory.Instance.LoadedDefaultPageData += new PageEventHandler(Instance_LoadedDefaultPageData);
}

protected void Instance_LoadedDefaultPageData(object sender, PageEventArgs e)
{
if (e.Page.PageTypeID == Utils.Settings.PageTypeJobitem && e.Page != null && e.Page.PageLink != PageReference.EmptyReference)
{
PageDataCollection languages = DataFactory.Instance.GetLanguageBranches(e.Page.PageLink);
if (languages.Count > 0)
{
e.Page.StartPublish = languages[0].StartPublish;
e.Page.StopPublish = languages[0].StopPublish;
}
}
}