Loading ...

page lyfecycle related issue explanation needed

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  web forms / data controls   » page lyfecycle related issue explanation needed

page lyfecycle related issue explanation needed

Posts under the topic: page lyfecycle related issue explanation needed

Posted: 2/12/2009

Lurker 39  points  Lurker
  • Joined on: 1/8/2009
  • Posts: 14

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


Posted: 2/16/2009

Contributor 4863  points  Contributor
  • Joined on: 11/27/2008
  • Posts: 79
  Answered

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


Posted: 2/16/2009

Lurker 39  points  Lurker
  • Joined on: 1/8/2009
  • Posts: 14

Got my answer. Thanks Vivek


Page 1 of 1 (3 items)