473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

code in InitializeComponent vanishes. Very frustrating


I've noticed that my code in InitializeComponent where I am linking
event handlers to events vanishes from time to time.

One of the things that triggers the disappearance is when I do something
wrong the the aspx page, causing an "Error Creating Control" error.
It's not always reproducible, but when I do that, some of the lines of
code in InitializeComponent vanish without warning.

Is this a "feature" from Microsoft? Is there a way to prevent that if
that is indeed a "feature"?

It is beyond frustrating because often it happens after my code has been
deployed and customers complain about buttons failing to respond. There
is no way I can audit every line of code in InitializeComponent to make
sure it has remained intact.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #1
3 1423
When you create a form with Visual Studio.NET, did you ever notice the
following comment that is added before the InitializeComponent Sub?
'NOTE: The following procedure is required by the Form Designer

'Do not modify it using the code editor.

You are doing exactly what it tells you not to do and then you are
frustrated by the outcome.

I suggest you move your custom code into some other place such as Page_Init
or Page_Load.

To be fair, you aren't the only one that's been confused by this and that's
why Microsoft is moving all that "no-touch" stuff into separate files in
Visual Studio 2005, so people won't be so tempted to muck with it and then
end up frustrated like you.
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


"David Cho" <pr********@yahoo.com> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...

I've noticed that my code in InitializeComponent where I am linking
event handlers to events vanishes from time to time.

One of the things that triggers the disappearance is when I do something
wrong the the aspx page, causing an "Error Creating Control" error.
It's not always reproducible, but when I do that, some of the lines of
code in InitializeComponent vanish without warning.

Is this a "feature" from Microsoft? Is there a way to prevent that if
that is indeed a "feature"?

It is beyond frustrating because often it happens after my code has been
deployed and customers complain about buttons failing to respond. There
is no way I can audit every line of code in InitializeComponent to make
sure it has remained intact.

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #2
Wait, hold on here, Steve.

I have not modified anything by hand. After creating a button by
dragging and dropping it into the form, I click on the button which
opens the code editor taking you to the click event handler auto
generated by VS.NET.

I have not done anything by hand in InitializeComponent. VS.NET
generates all the code that links event handlers to events.

At times even

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

vanishes.

I am not understanding your point. Microsoft generates the event
handlers and links them to events, but the code vanishes because....?

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #3
OK, so you didn't modify the code in there. Good.

Many of us have been frustrated by C#'s bad habit of deleting such event
handlers. I'ts one of the reasons I prefer VB.NET The only time I've seen
such a problem in VB.NET is when I cut a control and then paste it. The
event handler is no longer linked up. I believe this also happens in C#,
but I think it can happen in C# for other mysterious reasons too. Source
control can help somewhat.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"David Cho" <pr********@yahoo.com> wrote in message
news:OB**************@tk2msftngp13.phx.gbl...
Wait, hold on here, Steve.

I have not modified anything by hand. After creating a button by
dragging and dropping it into the form, I click on the button which
opens the code editor taking you to the click event handler auto
generated by VS.NET.

I have not done anything by hand in InitializeComponent. VS.NET
generates all the code that links event handlers to events.

At times even

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

vanishes.

I am not understanding your point. Microsoft generates the event
handlers and links them to events, but the code vanishes because....?

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Cooper | last post by:
Hello all, This is an extremely frustrating issue. I have a datagrid that is populated with three different custom datagridtextboxcolumns that I inherited they all work perfectly, while the...
0
by: Patrick Corkum | last post by:
Hello, I am having a really annoying problem. I have a base form, say FormA, and this form has some buttons on it with images (which are stored in the resx file). I then have FormB, which...
0
by: Ryan Liu | last post by:
I think there are two way to define user control. For example, I want to define a ComoBox with contains only AM, PM items. a.. One way I define a class extends...
3
by: Tabo | last post by:
when i build the project using C#, the code in InitializeComponent lost sometimes. Is it a bug?? if yes, can some method fix it? thanks for help. Tabo
8
by: edster | last post by:
A *lot* of our teams code is being deleted from the InitializeComponent() section of a winform, such as Grid settings, event handler hooks, layout settings etc. This mainly seems to happen to 3rd...
2
by: Andre | last post by:
I'm trying to add a asp.net page which will act as a contact-me e-mail form to keep our e-mail addresses hidden from page visitors. I've created a combo/drop down box listing our various...
1
by: David | last post by:
I am sure this falls under the "beaten to death" category, but I finally got around to post the question after getting fed up with it. I know that the code in InitializeCompoent shouldn't be...
3
by: Scott Kilbourn | last post by:
Hi, I added some custom code to the InitalizeComponent function of a control that I'm working on. Every once in a while, I've noticed that the code that I added disappears. I finally tracked...
6
by: cj | last post by:
Lets just take this example I'm looking at now. I'm looking at the help screen titled .NET Framework Class Library FolderBrowserDialog Class . It gives an example at the bottom that begins with:...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.