• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1061
  • Last Modified:

Hook into DataBind

My DataBind method is not being invoked.

The web control:
<myms:ToolbarButton runat="server" id="tbNext" datasource="<%# myDataSet %>"></myns:ToolbarButton>

Code behind:
namespace Somewhere
{
    public class ToolbarButton : Microsoft.Web.UI.WebControls.ToolbarItem
    {
        public event EventHander DataBinding;
        public Control BindingContainer
        {
            get { return this.ParentToolbar.NamingContainer }
        }

        private object _ds = null;
        public object DataSource
        {
            get { return _ds; }
            set { _ds = value; }
        }

        public virtual void DataBind ( )
        {
            if (DataBinding) { DataBinding(this, new EventArgs( )): }
            // ...
        }
    }
}

Problem is, DataBind never gets invoked. Even though the page contains a this.DataBind( ) call in Page_Load. All the other controls seem to get bound Ok, but not mine.

Extra details:
- Base class is NOT System.Web.UI.Control. It's one of the Microsoft internet web controls. As such I had to implement DataBinding and BindingContainer manually [took ages to figure out this was why my control wouldn't parse].
- On the parent page myDataSet is only initialised within Page_Load, so I can't use <%= ... %> .
- My class doesn't recieve events from the parent control/page, so I can't listen for something to happen. Within my constructor ParentToolbar isn't initialised yet, so I have no access to it or the parent Page.

Overriding Render is the best I can come up with to ensure that I perform a psuedo DataBind, but my DataSource is never called and therefore my DataSource is always null. Failing this a direct:

tbNext.DataSource = myDataSet;
tbNext.DataBind ( );

within the Page_Load of the parent page works, but it sure ain't pretty, considering that a this.DataBind ( ) is invoked anyhow (for other controls). Providing a separate Init ( ) method is an ugly alternative to a neat feature as DataBind, but it's a last resort.

Is there an Attribute I'm possibly missing, or is there some other means of hooking into DataBind( ) ?
0
_ys_
Asked:
_ys_
1 Solution
 
_ys_Author Commented:
Turns out the answer was in my post --> Base class is NOT System.Web.UI.Control.

So I'm not in the control tree for the page. Of course my DataBind doesn't get invoked.

Rolling out a custom implementation of Microsoft.Web.UI.WebControls.Toolbar and propogating the DataBind( ) onto my buttons did the trick. A simple this.DataBind( ) on the page therefore works a treat. No hack required.
0
 
moduloCommented:
Closed, 500 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now