Tuesday, February 16, 2010

aspx 3.5 WebControl OnInit() never being fired

i am currently doing something in visual studio wed developer express.  I have a simple web page with referencing a simple WebControl.  In the MasterPage.master.cs file in the web site in my OnInit I call the WebControl instantiation and to my surpirse the overrided OnInit method in the WebControl is never entered.  It skips right over it.

Anyone see anything like this? don't read into the code, this is only a simple test to see the implementation working.  It is going to be more than a Dictionary object with one key and a List of values.  In the end it will be a Multi-keyed dictionary object.


Master.master.cs snippet
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        MyTestControl = new MyControl();
        MyTestControl.AddGroup();
    }


MyControl.cs snippet
    public class MyControl : WebControl
    {
        private Dictionary> _myDict = new Dictionary>();

        public enum dKey
        {
            Group,
            User
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            _myDict[dKey.Group] = new List();
        }

       
        public void AddGroup()
        {
            Group grp = new Group("test", "test");

            _myDict[dKey.Group].Add(grp);
        }
    }

No comments: