Im aware this may be a slightly odd question, but given a Page class that looks like this:
public class abc:Control
{
public abc()
{
this.Init+=new EventHandler(foo);
this.Load+=new EventHandler(foo);
}
void foo(object sender, eventargs e)
{
//determine whether or not this.Init has already fired.
}
}
I know I could do this by setting a global boolean ‘hasinitfired’, but I was wondering if this was not necessary or if something as part of the .net library already existed.
Why do you need to know init is fired or not. Init always gets fired during postback or callback. Go through ASP.net page lifecycle, and you will know what all events fired after init and what all before. If you intend to use same handler for different events, yes make a class variable to identify the current event. I recommend attach different handler, and call another method with different param value.
like,
This will give cleaner solution and flexibility to add functionality.