By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

Visual Studio and PreInit handler

P: n/a
WT
Is it normal that Visual Studio sets the PreInit handler for a Page from the
OnInit code ?
No chance to fire it as OnPreInit is run befor OnInit.

???

CS
Feb 12 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
That doesn't sound right.....maybe your ASP.NET templates got messed up?

What does it look like?

karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"WT" <WT@newsgroups.nospamwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
Is it normal that Visual Studio sets the PreInit handler for a Page from
the OnInit code ?
No chance to fire it as OnPreInit is run befor OnInit.

???

CS
Feb 12 '07 #2

P: n/a
WT
Hi Karl, Thanks for answer, where to check this template ?
CS
"Karl Seguin [MVP]" <ka********@removeopenmymindremovemetoo.andmenet a
écrit dans le message de news: ev**************@TK2MSFTNGP04.phx.gbl...
That doesn't sound right.....maybe your ASP.NET templates got messed up?

What does it look like?

karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"WT" <WT@newsgroups.nospamwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
>Is it normal that Visual Studio sets the PreInit handler for a Page from
the OnInit code ?
No chance to fire it as OnPreInit is run befor OnInit.

???

CS

Feb 12 '07 #3

P: n/a
Hello CS,

Do you mean when you use Visual Studio to develop ASP.NET 2.0 web page, the
IDE automatically add the "PreInit" handler's registering code in "OnInit"
function?

Generally, for ASP.NET 2.0 web pages, since the "AutoWireupEvent" is set to
"true", we simply add the event handler function in codebehind(with the
expected naming convention) and the runtime will automatically attach the
handler to the page's corresponding event. e.g.
public partial class nav_menupage : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
Response.Write("<br/>Page_PreInit.....");
}

....................
}
Is this behavior not working in your development environment?

Please feel free to let me know your detailed scenario so that we can
perform some further research on this.

Look forward to your reply.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.

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

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

Feb 13 '07 #4

P: n/a
WT
Hello Steven,

Yes, the IDE is generating the PreInit in OnInit, more prcesely in the
InitializeComponent that is sent by preInit.
My projet is a Web Application, I am using Visual Studio Pro with SP1 on a
XP laptop, using C#, following are informations from VS.

For majority of my aspx pages AutoEventWireUp is turned off.
I followed this process: open the aspx page, choose Design mode, then from
right click menu choose View Component Designer (I have not found another
way to display the page properties with handlers), then right click again
and Properties, then Events button, then double click in the PreInit.
Switcing back to the code windows, I cans see the generated code:

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

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.PreInit += new System.EventHandler(this.DesktopDefault_PreInit);

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

}

#endregion

private void DesktopDefault_PreInit(object sender, EventArgs e)

{

}

It seems a bug.

Here are My VS infos.

Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: Professional

Microsoft Visual Basic 2005 77626-009-0000007-41381
Microsoft Visual Basic 2005

Microsoft Visual C# 2005 77626-009-0000007-41381
Microsoft Visual C# 2005

Microsoft Visual Studio Tools for Office 77626-009-0000007-41381
Microsoft Visual Studio Tools for the Microsoft Office System

Microsoft Visual Web Developer 2005 77626-009-0000007-41381
Microsoft Visual Web Developer 2005

Microsoft Web Application Projects 2005 77626-009-0000007-41381
Microsoft Web Application Projects 2005
Version 8.0.50727.762

Crystal Reports AAC60-G0CSA4B-V7000AY
Crystal Reports for Visual Studio 2005
Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1
(KB926601)
This service pack is for Microsoft Visual Studio 2005 Professional Edition -
ENU.
If you later install a more recent service pack, this service pack will be
uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601

SQL Server Analysis Services
Microsoft SQL Server Analysis Services Designer
Version 9.00.2047.00

SQL Server Integration Services
Microsoft SQL Server Integration Services Designer
Version 9.00.1399.00

SQL Server Reporting Services
Microsoft SQL Server Reporting Services Designers
Version 9.00.1399.00

"Steven Cheng[MSFT]" <st*****@online.microsoft.coma écrit dans le message
de news: Gk****************@TK2MSFTNGHUB02.phx.gbl...
Hello CS,

Do you mean when you use Visual Studio to develop ASP.NET 2.0 web page,
the
IDE automatically add the "PreInit" handler's registering code in "OnInit"
function?

Generally, for ASP.NET 2.0 web pages, since the "AutoWireupEvent" is set
to
"true", we simply add the event handler function in codebehind(with the
expected naming convention) and the runtime will automatically attach the
handler to the page's corresponding event. e.g.
public partial class nav_menupage : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
Response.Write("<br/>Page_PreInit.....");
}

....................
}
Is this behavior not working in your development environment?

Please feel free to let me know your detailed scenario so that we can
perform some further research on this.

Look forward to your reply.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.

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

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

Feb 13 '07 #5

P: n/a
Thanks for your reply CS,

I've performed some tests in my local environment, also a XP/sp2 box with
vs 2005 SP1 installed. However, the result I got is a bit different. When I
select and double click to generate an event handler (for PreInit for
instance), it did add the "InitializeComponent" function and with the code
that register the handler, however, the difference is that the "OnInit"
method is not generated and the "InitializeComponent" method is not called
by any other function.

Here is the complete generated code (codebehind and codebehind.designer...)
in my test environment:

==========codebehind==============
namespace TestWebAppProj
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

private void InitializeComponent()
{
this.PreInit += new System.EventHandler(this._Default_PreInit);

}

private void _Default_PreInit(object sender, EventArgs e)
{

}
}
}
====================================

==========codebehind.designer==================

namespace TestWebAppProj
{

public partial class _Default
{
protected System.Web.UI.HtmlControls.HtmlForm form1;
}
}
=============================================

Have you tested on some other box with VS 2005 SP1installed to see whether
they have the same behavior?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.



Feb 14 '07 #6

P: n/a
WT
Heloo Steven,

Thanks again for feedback.
Concerning your question, I am actually porting 1.1 code to 2 and in
majority of files the OnInit handler exist because we are with
AutoEventWireup=false.
And when the InitializeComponent is already existing and called inside
OnInit, then VS does no check for this and adds it delegate in
InitializeComponent which is badly called.
Seems a problem.

CS

"Steven Cheng[MSFT]" <st*****@online.microsoft.coma écrit dans le message
de news: Jm*************@TK2MSFTNGHUB02.phx.gbl...
Thanks for your reply CS,

I've performed some tests in my local environment, also a XP/sp2 box with
vs 2005 SP1 installed. However, the result I got is a bit different. When
I
select and double click to generate an event handler (for PreInit for
instance), it did add the "InitializeComponent" function and with the code
that register the handler, however, the difference is that the "OnInit"
method is not generated and the "InitializeComponent" method is not called
by any other function.

Here is the complete generated code (codebehind and
codebehind.designer...)
in my test environment:

==========codebehind==============
namespace TestWebAppProj
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

private void InitializeComponent()
{
this.PreInit += new System.EventHandler(this._Default_PreInit);

}

private void _Default_PreInit(object sender, EventArgs e)
{

}
}
}
====================================

==========codebehind.designer==================

namespace TestWebAppProj
{

public partial class _Default
{
protected System.Web.UI.HtmlControls.HtmlForm form1;
}
}
=============================================

Have you tested on some other box with VS 2005 SP1installed to see whether
they have the same behavior?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.





Feb 14 '07 #7

P: n/a
Thanks for your followup CS,

So I've understood your complete scenario. Yes, VS 2003/asp.net 1.1 project
used to put the "InitializeComponents" function call in OnInit method(for
C#). It is obviously that this behavior is incorrect for VS 2005/asp.net
2.0 project since we need to put it in earlier event. I think put it in
class's constructor should be ok.

I think this one of those convertion problems that need to be improved for
the Web Application project. You're encouraged to submit such issues to the
feedback center so that the dev team can hear more on this.

http://connect.microsoft.com/feedbac...spx?SiteID=210

Thanks for your feedback and comments.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 15 '07 #8

P: n/a
WT
Reported.
CS
"Steven Cheng[MSFT]" <st*****@online.microsoft.coma écrit dans le message
de news: S2**************@TK2MSFTNGHUB02.phx.gbl...
Thanks for your followup CS,

So I've understood your complete scenario. Yes, VS 2003/asp.net 1.1
project
used to put the "InitializeComponents" function call in OnInit method(for
C#). It is obviously that this behavior is incorrect for VS 2005/asp.net
2.0 project since we need to put it in earlier event. I think put it in
class's constructor should be ok.

I think this one of those convertion problems that need to be improved for
the Web Application project. You're encouraged to submit such issues to
the
feedback center so that the dev team can hear more on this.

http://connect.microsoft.com/feedbac...spx?SiteID=210

Thanks for your feedback and comments.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Feb 16 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.