Results 1 to 3 of 3

Thread: When to bind with BindingManager

  1. #1
    Join Date
    Sep 2005
    Posts
    16

    Default When to bind with BindingManager

    In our system, we have been retrieving objects from the Session and use the DataBindings to set Control Values (TextBoxes, etc.) from the Properties of Objects retrieved from the Session.

    But, the IntializeDataBindings happens before the base.OnLoad method, which causes our Properties to fail.

    Would there be any issue to have the OnLoad methods for Page and UserControl to call
    base.OnLoad(e);
    before the
    BindingManager.BindSourceToTarget(this, Controller, validationErrors);
    method?

    Or is there a better way to do what we are trying to do?

    Thanks,
    Jamie

    Here's code example what I'm trying to do:

    public partial class TestContainerPage : Spring.Web.UI.Page
    {
    private TestObject testObject;

    protected override void InitializeDataBindings()
    {
    BindingManager.AddBinding("PageTextBox.Text", "TestName");
    }

    protected void Page_Load(object sender, System.EventArgs e)
    {
    object obj = this.Session["MyTestObject"];
    if (obj != null)
    {
    this.testObject = obj as TestObject;
    }
    }

    public string TestName
    {
    get
    {
    return this.testObject.Name;
    }

    set
    {
    this.testObject.Name = value;
    }
    }
    }

  2. #2
    Join Date
    Aug 2006
    Posts
    5

    Default

    I am not shure what you are trying to achieve. But if you just want your sessionstored objects back in their domain objects before spring assigns them there values, than override the OnLoad() method. Something like this.

    Code:
    public partial class TestContainerPage : Spring.Web.UI.Page
        {
             private TestObject myObject = new Object();
    
             protected override void InitializeDataBindings()
             {
                 BindingManager.AddBinding("PageTextBox.Text", "MyObject.Name");
             }
    
              protected void Page_Load(object sender, System.EventArgs e)
              {
                  
                      Session.Add("MyObject",MyObject);
              }
              protected override void OnLoad(EventArgs e)
              {
                 if ((User)Session["MyObject"] != null)
                 {
                     MyObject = (TestObject)Session["MyObject"];
                 }
                 base.OnLoad(e);
             }
              public string MyObject
              {
                   get
                   {
                       return myObject; 
                   }
    
                   set
                   {
                       this.myObject;
                   }
              }
    }

  3. #3
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    Have you tried something like that :

    Code:
    protected override void InitializeDataBindings()
    {
       BindingManager.AddBinding("PageTextBox.Text", "Session['MyTestObject'].Name");
    }
    Where Session["MyTestObject'] is already set elsewhere.

    You can also use ASP.NET injection to set it :
    (Don't forget that Session is a Page's property like another one.)
    Code:
    <object id="MyTestObject" type="TestObject, App_Code"/>
    
    <object type="MyPage.aspx">
      <property name="Session['MyTestObject']" ref="MyTestObject"/>
    </object>

    Hope this help,
    Bruno
    Last edited by Bruno Baia; 08-30-2006 at 04:17 PM.
    My english is as poor as my taylor is rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •