I've got an issue involving a website that I have been using VS 2008 for, until a few months ago when I bought VS 2010. 开发者_StackOverflow社区I did not 'upgrade' the website -- VS 2010 asked me if I wanted to, and I said 'no'. I ran into a problem the first time I tried to use VS 2010 to edit this website -- found a work-around that has been working for the past 3 months. But now, all of a sudden, the work-around seem to be failing.
When working on a website from the design window (either 2008 or 2010), you can double-click, for example, a button and it will open the code-behind for the button's on-click event.
For some reason that I have not figured out yet, VS 2010 decides to make a brand-new event sub, in addition to the one I've already got. For example, I've got a button with an on-click event (Created in VS 2008) like this:
Protected Sub btn_next_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_next.Click
...
End Sub
As soon as I open the website in VS2010, and double-click the button in the design window, it creates a brand new event (duplicating all of the code inside the 'sub / end sub') like this:
Protected Sub btn_next_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_next.Click
...
End Sub
(notice that in the duplicate event sub it changes the name of the sub by adding a '1')
If I delete the duplicate sub, it just comes back next time I double-click the button in the designer.
Not to mention, if I delete the duplicate sub and try to build the website, I get an error telling me it can't find 'Sub btn_next_Click1...'. (I've verified that the button's markup does not have an 'onclick=...' attribute that would force it to look for this specific sub.
Finally, If I leave the duplicate sub there...the event is handled twice (the original sub runs once, and the duplicate sub runs once, since they both 'handle' the same event).
My work-around was to delete the original sub. That seemed to work for a time. But ever since I re-published the app yesterday, the duplicate sub has started running twice, even though the original sub has been deleted. I've verified this by adding stops in the debugger, and then stepping-through each line. This work-around, which has worked for a few months, all of a sudden isn't working. Whatever I've done to cause it, I can't see it.
BTW -- the 're-publish' I'm referring two was for a different page int he website. The page that's got the problem I'm talking about in this post hasn't been modified for months, and has been working fine all this time.
Any experience with this? Am I going to have to re-code my app from scratch in VS 2010?
I don't think this is related to moving from 2008 to 2010. I get this from time to time as a result of edits that confuse the IDE.
The answer is to delete the original. The reason a "1" is appended is because one without the "1" exists. Deleting the original fixes that.
If that causes errors, you may need to edit the designer code directly.
精彩评论