Init event for control doesn't fire

S

Shimon Sim

I have Panel control on the page. I am handling Init event for it. It
doesn't seem to fire at all. Why?
Thank you
Shimon.
 
S

Shimon Sim

Like this. All of them fire except for Init
#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

this.Betterpanel2.Load += new System.EventHandler(this.Betterpanel2_Load);

this.Betterpanel2.Unload += new
System.EventHandler(this.Betterpanel2_Unload);

this.Betterpanel2.PreRender += new
System.EventHandler(this.Betterpanel2_PreRender);

this.Betterpanel2.Init += new System.EventHandler(this.Betterpanel2_Init);

this.Betterpanel2.Disposed += new
System.EventHandler(this.Betterpanel2_Disposed);

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{


this.Disposed += new
System.EventHandler(this.CompositeControlTest_Disposed);

this.Unload += new System.EventHandler(this.CompositeControlTest_Unload);

this.Load += new System.EventHandler(this.Page_Load);

this.Init += new System.EventHandler(this.CompositeControlTest_Init);

this.PreRender += new
System.EventHandler(this.CompositeControlTest_PreRender);

}

#endregion
 
B

Brock Allen

Well, that explains it :)

Child controls' OnInit is called before the Page's OnInit. You're registering
for the events too late. You can put <asp:panel OnInit="MyEventHandler" ...
/> into the ASP directly and that will register your event handler when the
contol is created.
 
S

Steven Cheng[MSFT]

Thanks for Brock's Great explanation and suggestions.

Hi Shimon,

Like Brock has mentioned, the OnInit event of the Page is too late for
registering event handler for sub control(added statically)'s Init event).
Because all the static sub control's Init event is fired when they are
being added into the parent container which is before the Page's OnInit
function. You can try using Brock's suggetion on registering the event
handler in aspx page inline.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)






--------------------
| Message-ID: <[email protected]>
| From: Brock Allen <[email protected]>
| Subject: Re: Init event for control doesn't fire
| References: <[email protected]>
| Mime-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 469.1
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Date: Fri, 12 Aug 2005 14:09:39 -0700
| NNTP-Posting-Host: c-66-30-185-175.hsd1.ma.comcast.net 66.30.185.175
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:117757
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Well, that explains it :)
|
| Child controls' OnInit is called before the Page's OnInit. You're
registering
| for the events too late. You can put <asp:panel OnInit="MyEventHandler"
...
| /> into the ASP directly and that will register your event handler when
the
| contol is created.
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|
|
|
| > Like this. All of them fire except for Init
| > #region Web Form Designer generated code
| > override protected void OnInit(EventArgs e)
| >
| > {
| >
| > //
| >
| > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
| >
| > //
| >
| > this.Betterpanel2.Load += new
| > System.EventHandler(this.Betterpanel2_Load);
| >
| > this.Betterpanel2.Unload += new
| > System.EventHandler(this.Betterpanel2_Unload);
| >
| > this.Betterpanel2.PreRender += new
| > System.EventHandler(this.Betterpanel2_PreRender);
| >
| > this.Betterpanel2.Init += new
| > System.EventHandler(this.Betterpanel2_Init);
| >
| > this.Betterpanel2.Disposed += new
| > System.EventHandler(this.Betterpanel2_Disposed);
| >
| > InitializeComponent();
| >
| > base.OnInit(e);
| >
| > }
| >
| > /// <summary>
| >
| > /// Required method for Designer support - do not modify
| >
| > /// the contents of this method with the code editor.
| >
| > /// </summary>
| >
| > private void InitializeComponent()
| >
| > {
| >
| > this.Disposed += new
| > System.EventHandler(this.CompositeControlTest_Disposed);
| >
| > this.Unload += new
| > System.EventHandler(this.CompositeControlTest_Unload);
| >
| > this.Load += new System.EventHandler(this.Page_Load);
| >
| > this.Init += new System.EventHandler(this.CompositeControlTest_Init);
| >
| > this.PreRender += new
| > System.EventHandler(this.CompositeControlTest_PreRender);
| >
| > }
| >
| > #endregion
| >
| > | >
| >> How are you registering for the Init event?
| >>
| >> -Brock
| >> DevelopMentor
| >> http://staff.develop.com/ballen
| >>> I have Panel control on the page. I am handling Init event for it.
| >>> It
| >>> doesn't seem to fire at all. Why?
| >>> Thank you
| >>> Shimon.
|

|
|
 
S

Steven Cheng[MSFT]

You're welcome Shimon,

Always feel free to post here if there are anything we can help you.
Have a good day!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Shimon Sim" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Init event for control doesn't fire
| Date: Tue, 16 Aug 2005 09:18:12 -0400
| Lines: 146
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:118236
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thank a lot Brock and Steven.
| I should have figured out the answer.
| Shimon.
| | > Thanks for Brock's Great explanation and suggestions.
| >
| > Hi Shimon,
| >
| > Like Brock has mentioned, the OnInit event of the Page is too late for
| > registering event handler for sub control(added statically)'s Init
event).
| > Because all the static sub control's Init event is fired when they are
| > being added into the parent container which is before the Page's OnInit
| > function. You can try using Brock's suggetion on registering the event
| > handler in aspx page inline.
| >
| > Thanks & Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| >
| > --------------------
| > | Message-ID: <[email protected]>
| > | From: Brock Allen <[email protected]>
| > | Subject: Re: Init event for control doesn't fire
| > | References: <[email protected]>
| > | Mime-Version: 1.0
| > | Content-Transfer-Encoding: 8bit
| > | Content-Type: text/plain; charset=iso-8859-1; format=flowed
| > | X-Newsreader: JetBrains Omea Reader 469.1
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | Date: Fri, 12 Aug 2005 14:09:39 -0700
| > | NNTP-Posting-Host: c-66-30-185-175.hsd1.ma.comcast.net 66.30.185.175
| > | Lines: 1
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:117757
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Well, that explains it :)
| > |
| > | Child controls' OnInit is called before the Page's OnInit. You're
| > registering
| > | for the events too late. You can put <asp:panel
OnInit="MyEventHandler"
| > ..
| > | /> into the ASP directly and that will register your event handler
when
| > the
| > | contol is created.
| > |
| > | -Brock
| > | DevelopMentor
| > | http://staff.develop.com/ballen
| > |
| > |
| > |
| > | > Like this. All of them fire except for Init
| > | > #region Web Form Designer generated code
| > | > override protected void OnInit(EventArgs e)
| > | >
| > | > {
| > | >
| > | > //
| > | >
| > | > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
| > | >
| > | > //
| > | >
| > | > this.Betterpanel2.Load += new
| > | > System.EventHandler(this.Betterpanel2_Load);
| > | >
| > | > this.Betterpanel2.Unload += new
| > | > System.EventHandler(this.Betterpanel2_Unload);
| > | >
| > | > this.Betterpanel2.PreRender += new
| > | > System.EventHandler(this.Betterpanel2_PreRender);
| > | >
| > | > this.Betterpanel2.Init += new
| > | > System.EventHandler(this.Betterpanel2_Init);
| > | >
| > | > this.Betterpanel2.Disposed += new
| > | > System.EventHandler(this.Betterpanel2_Disposed);
| > | >
| > | > InitializeComponent();
| > | >
| > | > base.OnInit(e);
| > | >
| > | > }
| > | >
| > | > /// <summary>
| > | >
| > | > /// Required method for Designer support - do not modify
| > | >
| > | > /// the contents of this method with the code editor.
| > | >
| > | > /// </summary>
| > | >
| > | > private void InitializeComponent()
| > | >
| > | > {
| > | >
| > | > this.Disposed += new
| > | > System.EventHandler(this.CompositeControlTest_Disposed);
| > | >
| > | > this.Unload += new
| > | > System.EventHandler(this.CompositeControlTest_Unload);
| > | >
| > | > this.Load += new System.EventHandler(this.Page_Load);
| > | >
| > | > this.Init += new
System.EventHandler(this.CompositeControlTest_Init);
| > | >
| > | > this.PreRender += new
| > | > System.EventHandler(this.CompositeControlTest_PreRender);
| > | >
| > | > }
| > | >
| > | > #endregion
| > | >
| > | > | > | >
| > | >> How are you registering for the Init event?
| > | >>
| > | >> -Brock
| > | >> DevelopMentor
| > | >> http://staff.develop.com/ballen
| > | >>> I have Panel control on the page. I am handling Init event for it.
| > | >>> It
| > | >>> doesn't seem to fire at all. Why?
| > | >>> Thank you
| > | >>> Shimon.
| > |
| >
| > |
| > |
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top