Loading ...

page lyfecycle related issue explanation needed | CodeAsp.Net

page lyfecycle related issue explanation needed

Posted in: ASP.NET Topics  »  Web Forms / Data Controls
Subscribe to RSS
  • joydeep157

    Hi,

    I have one web form. In the webform i  have overrided Control.AddedControl method like below,

     protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("This is the page load event</br>");


        }
       
        protected override void AddedControl(Control control, int index)
        {
            Response.Write("we are in AddedControl eventhandler</br>");
        }

    I am getting the output as,

    we are in AddedControl eventhandler
    we are in AddedControl eventhandler
    we are in AddedControl eventhandler
    we are in AddedControl eventhandler
    we are in AddedControl eventhandler
    This is the page load event

     

    Now i have overrided one more method AddParsedSubObject like below,

     protected override void protected override void AddParsedSubObject(object obj)
        {
            Response.Write("we are in AddParsedSubObject eventhandler</br>");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("This is the page load event</br>");


        }
       
        protected override void AddedControl(Control control, int index)
        {
            Response.Write("we are in AddedControl eventhandler</br>");
        }(object obj)
        {
            Response.Write("we are in AddParsedSubObject eventhandler</br>");
        }
            
       Now the output is,

    we are in AddParsedSubObject eventhandler
    we are in AddParsedSubObject eventhandler
    we are in AddParsedSubObject eventhandler
    we are in AddParsedSubObject eventhandler
    we are in AddParsedSubObject eventhandler
    This is the page load event

     

    After adding the AddParsedSubObject  method if i try to debug the code, execution is not comming in the AddedControl method. The output shows that clearly.

    can anyone explain that?

    Thanks in advance

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers

    To be a good programmer you have to be a good man first

    To be a good programmer you have to be a good man first.
     
  •   Answered
    vivek_iit

    The reason for this behavior is that AddedControl event is a sub-event of AddedParsedSubObject event. So if you are overriding AddedParsedObject, overrriden AddedControl wont fire as it is nested inside AddedParseSubObject.

    HTH,

    Vivek

    Help out people by contributing more in the community!
     
  • joydeep157

    Got my answer. Thanks Vivek

    To be a good programmer you have to be a good man first.
     
  • Page 1 of 1 (3 items)