Revisiting AutoEventWireup
Revisiting AutoEventWireup
am 16.01.2008 04:40:32 von gnewsgroup
I know that enough has been written/talked about AutoEventWireup.
I've read the MSDN documentation about AutoEventWireup, which turns
out to be very brief.
I've also googled and read quite many articles/conversations about
this topic. I am still confused. Here are my questions:
1. Is it the case that only Page_* (e.g. Page_Load, Page_Init,
Page_PreRender, etc.) events are relevant with regard to
AutoEventWireup? In other words, this has nothing to do with, for
example, the Click event of a Button?
2. I created a very simple application, whose code-behind looks like
this:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("hola, and how is it going?");
}
// The ID of the Button is btnSubmit in the aspx page.
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblMessage.Text = TextBox1.Text;
}
}
If I set AutoEventWireup=false, Page_Load is not executed and I don't
see "hola, and how is it going?" in the browser. This message shows
up when AutoEventWireup=true.
This is understood.
But, then * with AutoEventWireup=false *, how do I manually wire up
Page_Load to the Load event? I tried adding the following right
before the Page_Load method:
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
The "hola, and how is it going?" message still does not show up in the
browser. I must not be doing the right thing, please kindly advise.
Thanks.
I have more questions to come regarding AutoEventWireup.
Re: Revisiting AutoEventWireup
am 16.01.2008 05:00:14 von gnewsgroup
On Jan 15, 10:40=A0pm, gnewsgroup wrote:
> I know that enough has been written/talked about AutoEventWireup.
> I've read the MSDN documentation about AutoEventWireup, which turns
> out to be very brief.
>
> I've also googled and read quite many articles/conversations about
> this topic. I am still confused. =A0Here are my questions:
>
> 1. Is it the case that only Page_* (e.g. Page_Load, Page_Init,
> Page_PreRender, etc.) events are relevant with regard to
> AutoEventWireup? =A0In other words, this has nothing to do with, for
> example, the Click event of a Button?
>
> 2. I created a very simple application, whose code-behind looks like
> this:
>
> public partial class _Default : System.Web.UI.Page
> {
> =A0 =A0 protected void Page_Load(object sender, EventArgs e)
> =A0 =A0 {
> =A0 =A0 =A0 =A0 Response.Write("hola, and how is it going?");
> =A0 =A0 }
>
> =A0 =A0 // The ID of the Button is btnSubmit in the aspx page.
> =A0 =A0 protected void btnSubmit_Click(object sender, EventArgs e)
> =A0 =A0 {
> =A0 =A0 =A0 =A0 lblMessage.Text =3D TextBox1.Text;
> =A0 =A0 }
>
> }
>
> If I set AutoEventWireup=3Dfalse, Page_Load is not executed and I don't
> see "hola, and how is it going?" in the browser. =A0This message shows
> up when AutoEventWireup=3Dtrue.
>
> This is understood.
>
> But, then * with AutoEventWireup=3Dfalse *, how do I manually wire up
> Page_Load to the Load event? =A0I tried adding the following right
> before the Page_Load method:
>
> private void InitializeComponent()
> =A0 =A0 {
> =A0 =A0 =A0 =A0 this.Load +=3D new System.EventHandler(this.Page_Load);
> =A0 =A0 }
>
> The "hola, and how is it going?" message still does not show up in the
> browser. =A0I must not be doing the right thing, please kindly advise.
> Thanks.
>
> I have more questions to come regarding AutoEventWireup.
Further reading online told me that I need to override the OnInit
method and call the InitializeComponent method in it. Like this:
protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
I learned that setting AutoEventWireup to true will cause a
performance hit, and it is suggested that we set AutoEventWireup to
false when we deploy our web application.
But, does this imply that we then will have to provide the overrided
OnInit method in each page whose Page_Load does have some stuff in
it? It sounds very cumbersome to me.
Re: Revisiting AutoEventWireup
am 16.01.2008 06:52:36 von Dina
On Jan 16, 8:40 am, gnewsgroup wrote:
> I know that enough has been written/talked about AutoEventWireup.
> I've read the MSDN documentation about AutoEventWireup, which turns
> out to be very brief.
>
> I've also googled and read quite many articles/conversations about
> this topic. I am still confused. Here are my questions:
>
> 1. Is it the case that only Page_* (e.g. Page_Load, Page_Init,
> Page_PreRender, etc.) events are relevant with regard to
> AutoEventWireup? In other words, this has nothing to do with, for
> example, the Click event of a Button?
>
> 2. I created a very simple application, whose code-behind looks like
> this:
>
> public partial class _Default : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> Response.Write("hola, and how is it going?");
> }
>
> // The ID of the Button is btnSubmit in the aspx page.
> protected void btnSubmit_Click(object sender, EventArgs e)
> {
> lblMessage.Text = TextBox1.Text;
> }
>
> }
>
> If I set AutoEventWireup=false, Page_Load is not executed and I don't
> see "hola, and how is it going?" in the browser. This message shows
> up when AutoEventWireup=true.
>
> This is understood.
>
> But, then * with AutoEventWireup=false *, how do I manually wire up
> Page_Load to the Load event? I tried adding the following right
> before the Page_Load method:
>
> private void InitializeComponent()
> {
> this.Load += new System.EventHandler(this.Page_Load);
> }
>
> The "hola, and how is it going?" message still does not show up in the
> browser. I must not be doing the right thing, please kindly advise.
> Thanks.
>
> I have more questions to come regarding AutoEventWireup.
try giving the form name in the event handler declaration like so...
this.Form1.Load += new System.EventHandler(this.Page_Load);
I think this should solve the problem...
Re: Revisiting AutoEventWireup
am 16.01.2008 14:34:21 von gnewsgroup
On Jan 16, 12:52 am, Dina wrote:
> On Jan 16, 8:40 am, gnewsgroup wrote:
>
>
>
> > I know that enough has been written/talked about AutoEventWireup.
> > I've read the MSDN documentation about AutoEventWireup, which turns
> > out to be very brief.
>
> > I've also googled and read quite many articles/conversations about
> > this topic. I am still confused. Here are my questions:
>
> > 1. Is it the case that only Page_* (e.g. Page_Load, Page_Init,
> > Page_PreRender, etc.) events are relevant with regard to
> > AutoEventWireup? In other words, this has nothing to do with, for
> > example, the Click event of a Button?
>
> > 2. I created a very simple application, whose code-behind looks like
> > this:
>
> > public partial class _Default : System.Web.UI.Page
> > {
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > Response.Write("hola, and how is it going?");
> > }
>
> > // The ID of the Button is btnSubmit in the aspx page.
> > protected void btnSubmit_Click(object sender, EventArgs e)
> > {
> > lblMessage.Text = TextBox1.Text;
> > }
>
> > }
>
> > If I set AutoEventWireup=false, Page_Load is not executed and I don't
> > see "hola, and how is it going?" in the browser. This message shows
> > up when AutoEventWireup=true.
>
> > This is understood.
>
> > But, then * with AutoEventWireup=false *, how do I manually wire up
> > Page_Load to the Load event? I tried adding the following right
> > before the Page_Load method:
>
> > private void InitializeComponent()
> > {
> > this.Load += new System.EventHandler(this.Page_Load);
> > }
>
> > The "hola, and how is it going?" message still does not show up in the
> > browser. I must not be doing the right thing, please kindly advise.
> > Thanks.
>
> > I have more questions to come regarding AutoEventWireup.
>
> try giving the form name in the event handler declaration like so...
>
> this.Form1.Load += new System.EventHandler(this.Page_Load);
>
> I think this should solve the problem...
Thanks, but you did not read my 2nd post.
Re: Revisiting AutoEventWireup
am 16.01.2008 16:49:00 von DavidAnton
If you specify AutoEventWireup = true, then only the events starting with
"Page_" are automatically wired to methods of the same name.
However, this is only one of many options for wiring events:
1. AutoEventWireup = true - affects only "Page_*" events.
2. AutoEventWireup = false and specify "Page_*" event wireups manually.
3. Override the "On..." methods of the base class.
4. Specify event wireups in the control's markup section on the page.
Note that with AutoEventWireup = true, you just need either Page_Init or you
override OnInit, not both. With AutoEventWireup = false, you should override
OnInit.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++ VB Edition: VB to C++/CLI
Instant C++ C# Edition: C# to C++/CLI
"gnewsgroup" wrote:
> On Jan 15, 10:40 pm, gnewsgroup wrote:
> > I know that enough has been written/talked about AutoEventWireup.
> > I've read the MSDN documentation about AutoEventWireup, which turns
> > out to be very brief.
> >
> > I've also googled and read quite many articles/conversations about
> > this topic. I am still confused. Here are my questions:
> >
> > 1. Is it the case that only Page_* (e.g. Page_Load, Page_Init,
> > Page_PreRender, etc.) events are relevant with regard to
> > AutoEventWireup? In other words, this has nothing to do with, for
> > example, the Click event of a Button?
> >
> > 2. I created a very simple application, whose code-behind looks like
> > this:
> >
> > public partial class _Default : System.Web.UI.Page
> > {
> > protected void Page_Load(object sender, EventArgs e)
> > {
> > Response.Write("hola, and how is it going?");
> > }
> >
> > // The ID of the Button is btnSubmit in the aspx page.
> > protected void btnSubmit_Click(object sender, EventArgs e)
> > {
> > lblMessage.Text = TextBox1.Text;
> > }
> >
> > }
> >
> > If I set AutoEventWireup=false, Page_Load is not executed and I don't
> > see "hola, and how is it going?" in the browser. This message shows
> > up when AutoEventWireup=true.
> >
> > This is understood.
> >
> > But, then * with AutoEventWireup=false *, how do I manually wire up
> > Page_Load to the Load event? I tried adding the following right
> > before the Page_Load method:
> >
> > private void InitializeComponent()
> > {
> > this.Load += new System.EventHandler(this.Page_Load);
> > }
> >
> > The "hola, and how is it going?" message still does not show up in the
> > browser. I must not be doing the right thing, please kindly advise.
> > Thanks.
> >
> > I have more questions to come regarding AutoEventWireup.
>
> Further reading online told me that I need to override the OnInit
> method and call the InitializeComponent method in it. Like this:
>
> protected override void OnInit(EventArgs e)
> {
> InitializeComponent();
> base.OnInit(e);
> }
>
> I learned that setting AutoEventWireup to true will cause a
> performance hit, and it is suggested that we set AutoEventWireup to
> false when we deploy our web application.
>
> But, does this imply that we then will have to provide the overrided
> OnInit method in each page whose Page_Load does have some stuff in
> it? It sounds very cumbersome to me.
>
Re: Revisiting AutoEventWireup
am 16.01.2008 20:16:21 von gnewsgroup
On Jan 16, 10:49 am, David Anton
wrote:
> If you specify AutoEventWireup = true, then only the events starting with
> "Page_" are automatically wired to methods of the same name.
> However, this is only one of many options for wiring events:
> 1. AutoEventWireup = true - affects only "Page_*" events.
Thank you. So my guess was correct regarding this point.
> 2. AutoEventWireup = false and specify "Page_*" event wireups manually.
> 3. Override the "On..." methods of the base class.
> 4. Specify event wireups in the control's markup section on the page.
>
> Note that with AutoEventWireup = true, you just need either Page_Init or you
> override OnInit, not both. With AutoEventWireup = false, you should override
> OnInit.
So, in other words, if we turn off AutoEventWireup for deployment, we
*do* have to add the overrided method OnInit to wireup the Page_Load
method, right? That's a lot of hassle.
> --http://www.tangiblesoftwaresolutions.com
> C++ to C#
> C++ to VB
> C++ to Java
> Instant C#: VB to C#
> Instant VB: C# to VB
> Instant C++ VB Edition: VB to C++/CLI
> Instant C++ C# Edition: C# to C++/CLI
>
Re: Revisiting AutoEventWireup
am 16.01.2008 20:46:00 von DavidAnton
You can either override the OnInit (and wireup Page_Load there), or you can
just override OnLoad - some people use this approach in C#. In VB, they get
around this via the 'Handles' clause on the method, which takes care the
wireup behind the scenes.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++ VB Edition: VB to C++/CLI
Instant C++ C# Edition: C# to C++/CLI
"gnewsgroup" wrote:
> On Jan 16, 10:49 am, David Anton
> wrote:
> > If you specify AutoEventWireup = true, then only the events starting with
> > "Page_" are automatically wired to methods of the same name.
> > However, this is only one of many options for wiring events:
> > 1. AutoEventWireup = true - affects only "Page_*" events.
>
> Thank you. So my guess was correct regarding this point.
>
> > 2. AutoEventWireup = false and specify "Page_*" event wireups manually.
> > 3. Override the "On..." methods of the base class.
> > 4. Specify event wireups in the control's markup section on the page.
> >
> > Note that with AutoEventWireup = true, you just need either Page_Init or you
> > override OnInit, not both. With AutoEventWireup = false, you should override
> > OnInit.
>
> So, in other words, if we turn off AutoEventWireup for deployment, we
> *do* have to add the overrided method OnInit to wireup the Page_Load
> method, right? That's a lot of hassle.
>
> > --http://www.tangiblesoftwaresolutions.com
> > C++ to C#
> > C++ to VB
> > C++ to Java
> > Instant C#: VB to C#
> > Instant VB: C# to VB
> > Instant C++ VB Edition: VB to C++/CLI
> > Instant C++ C# Edition: C# to C++/CLI
> >
>