Try our conversational search powered by Generative AI!

Set default value to custom property

Vote:
 
I have created a longstring custom property that gives me a xhtml editor. So far so good but i need help with two things.
First i would like to fill the property with a default value . I've looked at a couple of blog post about this but can't seem to get it right. 
Second i would want to render the custom property as a regular textbox that can hold a lage string.
[Serializable]
    [PageDefinitionTypePlugIn]
    public class CustomerTypeBox : EPiServer.Core.PropertyLongString
    {

public override IPropertyControl CreatePropertyControl()
        {
            return new CustomerTypeBoxControl();
        }

}

  

public class CustomerTypeBoxControl : EPiServer.Web.PropertyControls.PropertyLongStringControl
    {
        
                
        protected override void  SetupEditControls()
        {
            base.SetupEditControls();        

        }
public CustomerTypeBox CustomerTypeBox
        {
            get
            {
                return PropertyData as CustomerTypeBox;
            }
        }
}

      

#47360
Jan 26, 2011 13:50
Vote:
 

To create a textbox you can use this code

[Serializable]

[PageDefinitionTypePlugIn()]

public class PropertyXhtmlBox : EPiServer.SpecializedProperties.PropertyXhtmlString

{

public override EPiServer.Core.IPropertyControl CreatePropertyControl()

{

return new PropertyXhtmlBoxControl();

}

}

public class PropertyXhtmlBoxControl : PropertyLongStringControl

{

public override EPiServer.Core.TableRowLayout RowLayout

{

get

{

return TableRowLayout.Default;

}

}

public override void CreateEditControls()

{

this.EditControl = this.CreateTextBox();

this.EditControl.ID = base.Name;

base.CopyWebAttributes(this.EditControl);

EditControl.CssClass = "";

this.Controls.Add(this.EditControl);

this.SetupEditControls();

}

protected override TextBox CreateTextBox()

{

TextBox box = new TextBox();

box.Width = Unit.Pixel(400);

box.Height = Unit.Pixel(100);

box.CssClass = "";

box.Text = this.ToString();

box.TextMode = TextBoxMode.MultiLine;

return box;

}

}

 

 

#47361
Jan 26, 2011 14:42
Vote:
 

The default value will only be triggered on new pages, and can be set in admin mode for the property

#47362
Jan 26, 2011 14:44
Vote:
 

Thank you Anders!

About the the default value, i want to read strings from a database and fill my textbox. Can that be done?

#47365
Jan 26, 2011 15:15
Vote:
 

It can be done, its possble to override the GetDefaultValue method on the PropertyData class

#47375
Jan 26, 2011 22:40
Vote:
 

Thanks again Anders, you've been very helpful! Just one more question...

If i, instead of a normal textbox, wants to show the strings with the possibility to remove a  marked string without saving the entire page. Is that also possible?

#47385
Jan 27, 2011 9:32
Vote:
 

Could you please explain a bit more?

#47387
Jan 27, 2011 9:45
Vote:
 

I will certainly try :)

What the customer want is when going to editmode, they want a textbox or listbox populated with a list of string that i get from a database based on a id on the current page.

Now they want a remove button next to the textbox to be able to delete a selected string in the textbox from the database in editmode without having to save and publish the page. Does this make sense?

Another question about the GetDefaultValue method, in order to get the data from the database i need to reach a property (id) on the current page that the custom propery is attached to. In my PropertyXhtmlBoxControl class i have the currentpage but not in the PropertyXhtmlBox class. How can i get to the currentpage in the control class?

#47389
Jan 27, 2011 10:13
Vote:
 

It sounds like that you want the values in the database to be the correct, and the value stored on the pages shouldnt matter.

you can access the database from the CreateEditControls

The id of the pages can be found by using this.Properties["PageLink"] from the Control class

If I where you I would have saved the new values to the database when a page is published. Hook up on the event PublishedPage

 

#47404
Jan 27, 2011 12:31
Vote:
 

That worked fine!

I can access the database in CreateEditControl but how do i get the output to the SetDefaultValue method in the other class?

#47424
Jan 27, 2011 16:54
* 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.