Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

VS.NET easts my events

I am basically at my wits end with this piece of junk.  For the 5th time this week it has eaten my stack of even handlers. I cannot figure out how to work around this! Argh!  Cna anything be done?

Sassy
Tuesday, June 22, 2004

We had the same problem on an ASP.NET app.  What we did to get around this issue was to create a custom method in the in the code behind page and placed all of our eventhandlers in the custom method and then call this method from the Page.OnInit method.

example:

override protected void OnInit(EventArgs e)
{
    InitializeComponent();
    CustomEvents(); //<---- Note
    base.OnInit(e);
}

private void CustomEvents()
{
    mycontrol.event += new somedelegate(somemethod);
}


Doing this stopped VS.NET from eating our eventhandler code.

Jeremy Howard
Tuesday, June 22, 2004

Sassy-

Where are  you placing your custom event declarations?  I've not had this happen, and want to avoid it...

Greg Hurlman
Tuesday, June 22, 2004

I put them in onInit.  I can't figure out exactly what causes this, it seems like it could be a result of changing from design / HTML mode, but I don't even use design mode...

Sassy
Tuesday, June 22, 2004

Jeremy, thanks, this looks perfect and ifs quite easy to do! Wish I didn't have to do it, but I'll take it.

I like using Bubble events exclusively because it lets me put the logic in the front controllers / page controllers rather than having the UI fire off stuff that may or may not have anything to do with that UI.  I use a lot os user controls and show / hide panels, so having the app logig in the ascx means digging around.

This way I just bubble the events to a simple default.aspx with no UI, that just handles button clicks and showing / hiding UI elements.

Sassy
Tuesday, June 22, 2004

Anythinginside that "designer generated code" region will get rewritten once you pop in/out of design mode.  Seems like Jeremy's answer is a good workaround though.

Greg Hurlman
Wednesday, June 23, 2004

That's why our company disables the "Design View" default when opening the page.  (We've witnessed the code eating ourselves)

Fast Eddie
Wednesday, June 23, 2004

I just use notepad.

This reminds me of that story about how the US space program spent millions developing a pen that would write in zero gravity, while in the Russian space program they just use pencils.

Devin
Thursday, June 24, 2004

Yeah, as others have suggested, just keep it in the code view. That's what I always do.

Steve Jones (UK)
Sunday, July 11, 2004

*  Recent Topics

*  Fog Creek Home