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

Failure to create event handler

P: n/a
I have a very simple web page (ASP.NET) that I am trying to build. On the
web page is a checkbox that enables or disables other controls based upon the
checked status. However, .NET fails to create the event handler for the
CheckedChanged event.

In addition, even if I manually create the event handler, the CheckedChanged
event is never executed at runtime. AutoPostBack is set to True. Sometimes,
..NET "loses" blocks of code that I have painstakingly created.

And, just to add to my fun, the IDE consistently goes "whacky" on me -
reserved words lose their highlighting in the middle of editing and
IntelliSense refuses to display lists of the events and methods for objects.

I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET and C#.
Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft .NET
Framework Version 1.1.4322 SP1

My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
Build 2195, SP4).

I must admit that I am VERY frustrated with this product - the IDE is buggy
as hell. If my company didn't insist upon using .NET, I would switch back to
VFP and be done with this nonsense once and for all.

Any help that is offered is *greatly* appreciated.

-RW-
Nov 19 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Richard,

Per haps you can show us your code, and we could help you figure out why the
event handler was never executed. The one major reason why it might be the
case is, the event handler was not registered with the control. This happens
if you remove the control from the page, using the IDE. So, if your event
handler looks like this

private void MyHandler(object sender, EventArgs e)
{
}

check for a line something like:

myControl.Load+= new EventHandler(MyHandler);

In almost all cases I have seen the event handlers not firing, the absence
of the above line has been the cause. The cause for this cause, is when you
remove a control from the page (in IDE), the IDE also removes all the
registered event handlers for that control.

Hope that helps!

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
I have a very simple web page (ASP.NET) that I am trying to build. On the
web page is a checkbox that enables or disables other controls based upon
the
checked status. However, .NET fails to create the event handler for the
CheckedChanged event.

In addition, even if I manually create the event handler, the
CheckedChanged
event is never executed at runtime. AutoPostBack is set to True.
Sometimes,
.NET "loses" blocks of code that I have painstakingly created.

And, just to add to my fun, the IDE consistently goes "whacky" on me -
reserved words lose their highlighting in the middle of editing and
IntelliSense refuses to display lists of the events and methods for
objects.

I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET and
C#.
Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft .NET
Framework Version 1.1.4322 SP1

My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
Build 2195, SP4).

I must admit that I am VERY frustrated with this product - the IDE is
buggy
as hell. If my company didn't insist upon using .NET, I would switch back
to
VFP and be done with this nonsense once and for all.

Any help that is offered is *greatly* appreciated.

-RW-

Nov 19 '05 #2

P: n/a
Manohar,

Thanks for the speedy reply! Here is the code I am using:
This is in the InitializeComponent()
this.CheckBox1.CheckedChanged += new EventHandler(CheckBox1_CheckedChanged)

This is the code that *should* fire when the CheckBox is clicked

private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
Debug.WriteLine("Checkbox1 was changed...");
}

This code never fires.

-RW-
"Manohar Kamath" wrote:
Richard,

Per haps you can show us your code, and we could help you figure out why the
event handler was never executed. The one major reason why it might be the
case is, the event handler was not registered with the control. This happens
if you remove the control from the page, using the IDE. So, if your event
handler looks like this

private void MyHandler(object sender, EventArgs e)
{
}

check for a line something like:

myControl.Load+= new EventHandler(MyHandler);

In almost all cases I have seen the event handlers not firing, the absence
of the above line has been the cause. The cause for this cause, is when you
remove a control from the page (in IDE), the IDE also removes all the
registered event handlers for that control.

Hope that helps!

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
I have a very simple web page (ASP.NET) that I am trying to build. On the
web page is a checkbox that enables or disables other controls based upon
the
checked status. However, .NET fails to create the event handler for the
CheckedChanged event.

In addition, even if I manually create the event handler, the
CheckedChanged
event is never executed at runtime. AutoPostBack is set to True.
Sometimes,
.NET "loses" blocks of code that I have painstakingly created.

And, just to add to my fun, the IDE consistently goes "whacky" on me -
reserved words lose their highlighting in the middle of editing and
IntelliSense refuses to display lists of the events and methods for
objects.

I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET and
C#.
Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft .NET
Framework Version 1.1.4322 SP1

My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
Build 2195, SP4).

I must admit that I am VERY frustrated with this product - the IDE is
buggy
as hell. If my company didn't insist upon using .NET, I would switch back
to
VFP and be done with this nonsense once and for all.

Any help that is offered is *greatly* appreciated.

-RW-


Nov 19 '05 #3

P: n/a
Manohar,

Thanks for the speedy reply! Here is the code I am using:
This is in the InitializeComponent()
this.CheckBox1.CheckedChanged += new EventHandler(CheckBox1_CheckedChanged)

This is the code that *should* fire when the CheckBox is clicked

private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
Debug.WriteLine("Checkbox1 was changed...");
}

This code never fires.

-RW-
"Manohar Kamath" wrote:
Richard,

Per haps you can show us your code, and we could help you figure out why the
event handler was never executed. The one major reason why it might be the
case is, the event handler was not registered with the control. This happens
if you remove the control from the page, using the IDE. So, if your event
handler looks like this

private void MyHandler(object sender, EventArgs e)
{
}

check for a line something like:

myControl.Load+= new EventHandler(MyHandler);

In almost all cases I have seen the event handlers not firing, the absence
of the above line has been the cause. The cause for this cause, is when you
remove a control from the page (in IDE), the IDE also removes all the
registered event handlers for that control.

Hope that helps!

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
I have a very simple web page (ASP.NET) that I am trying to build. On the
web page is a checkbox that enables or disables other controls based upon
the
checked status. However, .NET fails to create the event handler for the
CheckedChanged event.

In addition, even if I manually create the event handler, the
CheckedChanged
event is never executed at runtime. AutoPostBack is set to True.
Sometimes,
.NET "loses" blocks of code that I have painstakingly created.

And, just to add to my fun, the IDE consistently goes "whacky" on me -
reserved words lose their highlighting in the middle of editing and
IntelliSense refuses to display lists of the events and methods for
objects.

I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET and
C#.
Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft .NET
Framework Version 1.1.4322 SP1

My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
Build 2195, SP4).

I must admit that I am VERY frustrated with this product - the IDE is
buggy
as hell. If my company didn't insist upon using .NET, I would switch back
to
VFP and be done with this nonsense once and for all.

Any help that is offered is *greatly* appreciated.

-RW-


Nov 19 '05 #4

P: n/a
Richard,

do you have viewstate enabled/disabled? The event wiring in asp.net is
based on having viewstate enabled

-Stefan

Nov 19 '05 #5

P: n/a
As far as manually adding the handler - are you re-adding the handler on
every load of the page? You need to.

You might want to reinstall VS.NET. I don't think what you are experiencing
is typical.

"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
I have a very simple web page (ASP.NET) that I am trying to build. On the
web page is a checkbox that enables or disables other controls based upon
the
checked status. However, .NET fails to create the event handler for the
CheckedChanged event.

In addition, even if I manually create the event handler, the
CheckedChanged
event is never executed at runtime. AutoPostBack is set to True.
Sometimes,
.NET "loses" blocks of code that I have painstakingly created.

And, just to add to my fun, the IDE consistently goes "whacky" on me -
reserved words lose their highlighting in the middle of editing and
IntelliSense refuses to display lists of the events and methods for
objects.

I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET and
C#.
Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft .NET
Framework Version 1.1.4322 SP1

My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
Build 2195, SP4).

I must admit that I am VERY frustrated with this product - the IDE is
buggy
as hell. If my company didn't insist upon using .NET, I would switch back
to
VFP and be done with this nonsense once and for all.

Any help that is offered is *greatly* appreciated.

-RW-

Nov 19 '05 #6

P: n/a
The EnableViewState property for the checkbox is set to True.
"Stefan" wrote:
Richard,

do you have viewstate enabled/disabled? The event wiring in asp.net is
based on having viewstate enabled

-Stefan

Nov 19 '05 #7

P: n/a
The handler is being created in the InitializeComponent() section. Are you
saying that this needs to be moved to the Page_Load section?

I have re-installed VS.NET 2 times in the past week - that was a ton of fun,
can't wait to do it again <g>.

-RW-

"Marina" wrote:
As far as manually adding the handler - are you re-adding the handler on
every load of the page? You need to.

You might want to reinstall VS.NET. I don't think what you are experiencing
is typical.

"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
I have a very simple web page (ASP.NET) that I am trying to build. On the
web page is a checkbox that enables or disables other controls based upon
the
checked status. However, .NET fails to create the event handler for the
CheckedChanged event.

In addition, even if I manually create the event handler, the
CheckedChanged
event is never executed at runtime. AutoPostBack is set to True.
Sometimes,
.NET "loses" blocks of code that I have painstakingly created.

And, just to add to my fun, the IDE consistently goes "whacky" on me -
reserved words lose their highlighting in the middle of editing and
IntelliSense refuses to display lists of the events and methods for
objects.

I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET and
C#.
Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft .NET
Framework Version 1.1.4322 SP1

My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
Build 2195, SP4).

I must admit that I am VERY frustrated with this product - the IDE is
buggy
as hell. If my company didn't insist upon using .NET, I would switch back
to
VFP and be done with this nonsense once and for all.

Any help that is offered is *greatly* appreciated.

-RW-


Nov 19 '05 #8

P: n/a
Are you having this problem only
- for this specific checkbox control?
- for this specific page?
- or for all controls (buttons/links ...)?

Also, do you do anything else "fancy" which could manipulate your
viewstate?
E.g. are you dynamically injecting controls to your page (ie. a page
decorator)
using an http module or any other mechanism? If so, this could corrupt
your
viewstate (which would lead to your event not firing) ...

Also, is there any other code that clears the CheckedChange delegate
(search for "CheckBox1.CheckedChanged")?

The code you posted definitely looks ok

Nov 19 '05 #9

P: n/a
If you are manually adding the event handler, then why would it be in
InitializeComponent? That code gets regenerated by VS.NET, you shouldn't be
writing your own code and putting it there.

"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:CC**********************************@microsof t.com...
The handler is being created in the InitializeComponent() section. Are
you
saying that this needs to be moved to the Page_Load section?

I have re-installed VS.NET 2 times in the past week - that was a ton of
fun,
can't wait to do it again <g>.

-RW-

"Marina" wrote:
As far as manually adding the handler - are you re-adding the handler on
every load of the page? You need to.

You might want to reinstall VS.NET. I don't think what you are
experiencing
is typical.

"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
>I have a very simple web page (ASP.NET) that I am trying to build. On
>the
> web page is a checkbox that enables or disables other controls based
> upon
> the
> checked status. However, .NET fails to create the event handler for
> the
> CheckedChanged event.
>
> In addition, even if I manually create the event handler, the
> CheckedChanged
> event is never executed at runtime. AutoPostBack is set to True.
> Sometimes,
> .NET "loses" blocks of code that I have painstakingly created.
>
> And, just to add to my fun, the IDE consistently goes "whacky" on me -
> reserved words lose their highlighting in the middle of editing and
> IntelliSense refuses to display lists of the events and methods for
> objects.
>
> I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET
> and
> C#.
> Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft
> .NET
> Framework Version 1.1.4322 SP1
>
> My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
> Build 2195, SP4).
>
> I must admit that I am VERY frustrated with this product - the IDE is
> buggy
> as hell. If my company didn't insist upon using .NET, I would switch
> back
> to
> VFP and be done with this nonsense once and for all.
>
> Any help that is offered is *greatly* appreciated.
>
> -RW-


Nov 19 '05 #10

P: n/a
Could it be because the "Initialize" is never called? See what the page's
"AutoEventWireup" is set to, and switch it between true and false to see if
that makes a difference.

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com...
Manohar,

Thanks for the speedy reply! Here is the code I am using:
This is in the InitializeComponent()
this.CheckBox1.CheckedChanged += new
EventHandler(CheckBox1_CheckedChanged)

This is the code that *should* fire when the CheckBox is clicked


private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
Debug.WriteLine("Checkbox1 was changed...");
}

This code never fires.

-RW-
"Manohar Kamath" wrote:
Richard,

Per haps you can show us your code, and we could help you figure out why
the
event handler was never executed. The one major reason why it might be
the
case is, the event handler was not registered with the control. This
happens
if you remove the control from the page, using the IDE. So, if your event
handler looks like this

private void MyHandler(object sender, EventArgs e)
{
}

check for a line something like:

myControl.Load+= new EventHandler(MyHandler);

In almost all cases I have seen the event handlers not firing, the
absence
of the above line has been the cause. The cause for this cause, is when
you
remove a control from the page (in IDE), the IDE also removes all the
registered event handlers for that control.

Hope that helps!

--
Manohar Kamath
Editor, .netBooks
www.dotnetbooks.com
"Richard W" <Ri******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
>I have a very simple web page (ASP.NET) that I am trying to build. On
>the
> web page is a checkbox that enables or disables other controls based
> upon
> the
> checked status. However, .NET fails to create the event handler for
> the
> CheckedChanged event.
>
> In addition, even if I manually create the event handler, the
> CheckedChanged
> event is never executed at runtime. AutoPostBack is set to True.
> Sometimes,
> .NET "loses" blocks of code that I have painstakingly created.
>
> And, just to add to my fun, the IDE consistently goes "whacky" on me -
> reserved words lose their highlighting in the middle of editing and
> IntelliSense refuses to display lists of the events and methods for
> objects.
>
> I am using Visual Studio .NET 2003 Enterprise Architect with ASP.NET
> and
> C#.
> Microsoft Development Environment 2003 Version 7.1.3088 and Microsoft
> .NET
> Framework Version 1.1.4322 SP1
>
> My PC (Dell OptiPlex GX280, 512MB RAM) is running Win2K Pro (Version 5,
> Build 2195, SP4).
>
> I must admit that I am VERY frustrated with this product - the IDE is
> buggy
> as hell. If my company didn't insist upon using .NET, I would switch
> back
> to
> VFP and be done with this nonsense once and for all.
>
> Any help that is offered is *greatly* appreciated.
>
> -RW-


Nov 19 '05 #11

P: n/a
Marina,

VS.Net is generating event handlers within the InitializeComponent()
method.
I understand Richard just added it manually because VS.Net did not add
it
in VS.Net.

At runtime it doesn't matter who put the code in InitializeComponent -
be it Richard, be it VS.Net, since the code looks ok, the event should
fire.

Regards
-Stefan

Nov 19 '05 #12

P: n/a
Yes, it should fire. But if VS.NET has had a change to regenerate that code,
it may have deleted it. Which is the reason there is that warning there not
to change that method.

My point was just that manually adding the handler should work just fine.
And that maybe the reason it isn't working is because it is being deleted
when the designer code is regenerated.

"Stefan" <Cl*********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Marina,

VS.Net is generating event handlers within the InitializeComponent()
method.
I understand Richard just added it manually because VS.Net did not add
it
in VS.Net.

At runtime it doesn't matter who put the code in InitializeComponent -
be it Richard, be it VS.Net, since the code looks ok, the event should
fire.

Regards
-Stefan

Nov 19 '05 #13

P: n/a
Stefan is correct, I manually put the code there because that's where VS.NET
is putting all the other event handler declarations. Tracing the code at
runtime shows that the declaration is being executed. However, the method it
declares never fires when I click the checkbox. Hence, my problem...

-RW-

"Stefan" wrote:
Marina,

VS.Net is generating event handlers within the InitializeComponent()
method.
I understand Richard just added it manually because VS.Net did not add
it
in VS.Net.

At runtime it doesn't matter who put the code in InitializeComponent -
be it Richard, be it VS.Net, since the code looks ok, the event should
fire.

Regards
-Stefan

Nov 19 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.