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( ) ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_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.
Closed, 500 points refunded.

Community Support Moderator
Experts Exchange

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.