Custom Section

Jun 1, 2010 at 5:43 PM

Hi Rickard,

I have a easy control that works fine. I now need the control to load XML based upon a value saved with the section. I have tried to copy the link list section copying the control, the code behind and the class in app_code. I then rename every linkList instance with my section name everywhere I could find it. But I cannot seem to get the section to show up in the drop down list. Do you have a sample new section that has a really simple setup that I could copy and use as a template going forward. Perhaps a simple text box only ?

Any help you can give me would be appreciated.

Thanks

Coordinator
Jun 7, 2010 at 5:06 PM

Hi gazmob

Ok I'll try to explain how it works.

The basics of a section is one dataclass that is placed below sections in app_code. That class must inherit Section<YourSectionName.DataClass>.
You also put a section usercontrol with the same name but inherit SectionControlBaseClass below SectionControls.
If you look at the simple example control below you'll see how easy this is.
A class that inherit Section must override Position, IsOnline and SearchResult to compile.
Below I added a string "MyValue" that can be called from the sectioncontrol later.
To get it to show up in PageExplorer with a custom name you edit the StringsRes.resx below App_GlobalResources and add the name ctl_MyClass_RssTitle with a value for eg. MyCustomClass(Or whateever you want), which also is the name that shows up in PageExplorer.
But to get it all to work you add a MyClass.ascx (UserControl) in SectionControls folder.

Here is the most basic section to create.

//Section below app_code/sections
 public class MyClass : Section<MyClass.Data>
    {
        public MyClass() : base() { }
        public MyClass(string id) : base(id) { }


        public override List<SearchResult> Search(string searchString, WebPage page)
        {
            List<SearchResult> list = new List<SearchResult>();
            return list;
        }

        public class Data
        {
            public Position Position;
            public bool IsOnline = false;
            public string MyValue;
        }

        public string MyValue
        {
            get { return _data.MyValue; }
            set { _data.MyValue = value; }
        }

        public override Position Position
        {
            get{ return _data.Position;}
            set{ _data.Position = value;}
        }

        public override bool IsOnline
        {
            get {return _data.IsOnline; }
            set {_data.IsOnline = value;}
        }
    }

 

//MyClass.ascx and MyClass.ascx.cs below SectionControls
public partial class SectionControls_MyClass : SectionControlBaseClass
{
    private MyClass _section;
    protected void Page_Load(object sender, EventArgs e)
    {
        //If you added a LiteralControl to this usercontrol you can call it like below.
        //MyLiteral.Text = _section.MyValue;
       //Or to save data. "Regulary in a save method"
       //_section.MyValue = txtMyValue.Text;
       //_section.SaveData();
    }

    public override bool HasAdminView
    {
        get { return true;} //or false if this section dont has edit controls;
    }

    public override string InfoUrl
    {
        get { return ""; }
    }

    public override ISection Section
    {
        get
        {
            return (MyClass)_section;
        }
        set
        {
            _section = (MyClass)value;
        }
    }
}

 

Happy programming. Please feel free to ask again if you cant get it to work. (Once you got it, it's so easy to create new sections) :-)
Regards, Rickard