Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Default value of Property Page

Vote:
 

Hi.

I'm trying to set the default value of the Page property to "The current page" but I can't get it to work.

Seeing as pressing the button for "The current page" sets the value of the hidden field to a dash (-), I thought that a dash could be used in the default value field, but I was wrong..

Has anyone else succeeded, hopefully in a simple way, to set the default value of the page property to the current page being created?

#56945
Feb 17, 2012 11:30
Vote:
 

Hi Kim, 

I assume you're using PTB? In that case, adding the following code to your Global.asax will make it possible for you to set DefaultValue="-" as a reference to itself.

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

void Instance_LoadedDefaultPageData(object sender, PageEventArgs e)
{
    if (e.Page is PageTypeBuilder.TypedPageData)
    {
        var query = from props in e.Page.GetType().BaseType.GetProperties()
                    let ptbDefaultValues = props.GetCustomAttributes(typeof(PageTypePropertyAttribute), true).OfType<PageTypePropertyAttribute>().Where(a => a.DefaultValue != null && !string.IsNullOrEmpty(a.DefaultValue as string)).ToList()
                    where e.Page[props.Name] == null //Property has no default value from DataFactory
                    && ptbDefaultValues.Count > 0
                    select new { props.Name, ptbDefaultValues.FirstOrDefault().DefaultValue };

        foreach (var prop in query)
        {
            e.Page.Property[prop.Name].ParseToSelf(prop.DefaultValue.ToString());
        }
    }
}

    

Hope this helps, let me know if you have any questions on this piece of code!

Karoline

#56978
Edited, Feb 20, 2012 11:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.