views:

235

answers:

0

I am trying to bind a public UserControl property to my model inside a parent page. I created a simple example to show what I am trying to do, you can see it on PasteBin or download it here

The problem it that UserControl's property not binding to model, please check UserControl code:

public partial class SpnTest : Spring.Web.UI.UserControl
{
        private string testProperty;
        public string TestProperty
        {
                get { return testProperty; }
                set { testProperty = (string)value; }
        }

        protected override void InitializeModel()
        {
                testProperty = "";
        }

        protected override void LoadModel(object savedModel)
        {
                testProperty = (string)savedModel;
        }

        protected override object SaveModel()
        {
                return testProperty;
        }

        protected override void InitializeDataBindings()
        {
                BindingManager.AddBinding("TextBox1.Text", "TestProperty").SetErrorMessage("TestProperty Binding error", "errProv.errors");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
}

And the parent page code:

using System;

public partial class SpnTest : Spring.Web.UI.Page
{
    public class Test
    {
     public string Property1 { get; set; }
     public string Property2 { get; set; }
    }

    private Test testObj;
    public Test TestObj
    {
     get { return testObj; }
     set { testObj = (Test)value; }
    }

    protected override void InitializeModel()
    {
     testObj = new Test();
     testObj.Property1 = testObj.Property2 = "";
    }

    protected override void LoadModel(object savedModel)
    {
     testObj = (Test)savedModel;
    }

    protected override object SaveModel()
    {
     return testObj;
    }

    protected override void InitializeDataBindings()
    {
     BindingManager.AddBinding("TextBox1.Text", "TestObj.Property1").SetErrorMessage("Property1 Binding error", "errProv.errors");
     BindingManager.AddBinding("SpnTestControl1.TestProperty", "TestObj.Property2").SetErrorMessage("Property2 Binding error", "errProv.errors");
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
     txtDebug.Text = string.Format("Property1 = {0}\nProperty2 = {1}", TestObj.Property1, TestObj.Property2);
    }

}