AutoEventWireup and PreInit

W

WT

Hello,
It seems that Page_PreInit is not run automatically when AutoEventWireUp is
set for the Page as it is for Page_Load or Page_Init.

Somebody could confirm this missing point ?

CS
 
S

Steven Cheng[MSFT]

Hello CS,

I've also seen your another thread "Visual Studio and PreInit handler" and
have posted in there. Is the problem here the same one as that thread?

As I've mentioned in that thread, for ASP.NET 2.0 page, as long as you set
the "AutoWireupEvent" to "true", you only need to put the correct named
page event handler function in codebehind and the runtime should
automatically register the event handler for you. And the "PreInit" is
surely of this case.

==============
public partial class nav_menupage : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
Response.Write("<br/>Page_PreInit.....");
}
.............
==============

Is there anything incorrect in the PreInit handler's definition or any
other programmatic code whch has turned of the "AutoEventWireup"?

BTW, for MasterPage and ascx usercontrol, they do not have "PreInit" event,
therefore, you should not put PreInit event handler in these two
components' codebehind.

Please feel free to let me know if there is anything else particular in
your scenario.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

WT

Steven,

My oiher thread is another problem.
Ok I was trying to use Page_PreInit in an ascx file.
I have switched to the property setting method after LoadControl you
suggested in another thread
I have moved the LoadControl in the PreInitEvent of the Page and it seems to
be Ok.

What I would ideally appreciated is to understand the detailled differences
in the Page and its Controls objects between the OnPreInit Step, the OnInit
step and the OnLoad.

Regards
CS
 
S

Steven Cheng[MSFT]

Thanks for your quick reply CS,

You can get a full list of the events available in UserControl here:

#UserControl Events
http://msdn2.microsoft.com/en-us/library/d6thxdk7.aspx

The reason why UserControl(also Control, WebControl) doesn't have the same
event collection as Page is because controls are loaded at a certain stage
in Page's lifecycle, this determines that Control's lifecycle certainly
begin after Page has done some certain intialization, so there are some
ealier events in Page's lifecycle which is not available to Web controls.
For example, at Page's PreInit stage, those child controls are not even
created and initialized(participate in the page processing pipeline), they
surely won't be able to utlize the "PreInit" event.

Here are two good msdn reference which are very helpful on understanding
the ASP.NET page and control's server-side process stages:

#ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

#Control Execution Lifecycle
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconControlExecutionLifecycle.asp

If you have any further questions on this, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Forum statistics

Threads
474,262
Messages
2,571,054
Members
48,769
Latest member
Clifft

Latest Threads

Top