I assume I am not the first one having this problem and I am normally pretty good at googling for stuff but in this case I didn't succeed in finding a solution, so I'll post it here.
I have some experience in VB.NET and WinForms, now I am working on an ASP.NET project and I decided to do it in C#, so I can learn more technologies / languages.
I have been creating even handlers for controls by clicking the "Events" lightning bolt on the Properties windows and then double-clicking on the event name. That automatically creates an event procedure, selects it for the handler and opens the code behind with the procedure declaration already there. It has been working fine until now. I just added a FormView object and I am trying to create a handler for the ItemCommand event. As usual, I am double-clicking on "ItemCommand" under Events and it populates it with "fvMembers_ItemCommand" but it does not jump to the code behind and it does not create the actual function. I just tried doing the same thing in a different project that was created by somebody else and it looks like it's working fine there.
Any suggestions?
Thanks!
The best recommendation for this is the following. Clear out the definition of the event, by right clicking and selecting "remove". Save any progress that you have, exit visual studio, and then go back to the project.
Be sure that you don't have any build errors then try it again. I've found that VS just needs a re-start every so often.
Now, don't I feel stupid :)
I didn't even have to close VS. I closed and re-opened the solution and it appears to be working now. I just had a situation yesterday where an ObjectDataSource wasn't reflecting the latest structure, "Refresh Schema" wasn't helping either. Rebulding the solution didn't help either but it helped restarting VS. I don't think I ever had to re-start VS while working on WinForms projects but it looks like working on ASP.NET requires frequent VS restarts.
Thank you for your help!
Related
I am developing an application using Visual Studio 2019 and I am designing winforms.
Visual Studio commonly crashes when I am creating the forms by freezing, and recently my designed winform has somehow disappeared (even though I saved it). When i open it it shows as the default winform that is shown when a new one is created:
When I browse the solution explorer it seems that I can still see all the components I had added to the form:
Finally, when I try to restart and manually add the components back, I get an error message saying that the component can't be added due to duplication - which is probably because they are somehow still there (as shown in the solution explorer) but the data has been corrupted somehow:
If anybody has any idea of how to recover the data and the winform, I would very much appreciate it. If any additional information is required, please let me know. Thanks!
According to your description, first, the controls actually exist, but they are not
displayed in the design window.
You can try to check whether the. add statement of each control added to the window still
exists in the .Design.cs file.
If not, you can add it manually.
Second, solution explorer shows the missing components, but there is an error in adding
components. It means that only the declaration of this control in the .Design.cs file does
not assign a value to this control. You can delete the declaration of the component in the
.Design.cs file, and then add the component in the design interface.
Result:
I'm new to C# and delegates, however, from what I've gathered, they say if this event happened run this method. But in Visual Studio (community 2017), I can't figure out where/how I am meant to go about defining/attaching them.
I'd appreciate an answer as I'm trying to go about switching a program I've previously written in Python over to C#.
I've looked through documentation, I've looked over questions already asked here, and none of them seem to give me the information I'm after.
To add delegates (in this case they're typically called "event handlers") to UI controls in WinForms, you should:
Select the control in the visual designer
Look at the Properties windows
Click the lightning bolt to view the events.
Either double-click the blank space next to an event to auto-generate a handler, or single-click and select an existing handler from the dropdown.
Everytime I accidentally doubleclick a webcontrol (ex GridView, DetailsView), VS creates an
unnecessary event in code (selectedindexchanged). I delete this event, but the reference still appears in webcontrol's properties, causing the CS1061 exception.
Is there a way to delete the reference in properties (or asp.net code) automatically when the event is deleted in C# code?
I know that when programming in VB, Visual Studio does it, so i'm looking for a similar solution in C#.
I've experienced the same problem as you before and while it's not really a problem, I feel your frustration when you run and then it all fails because you forgot to remove the code from the .aspx.
Unfortunately there's no way to change this behavior. No automatic way to do it, anyway. I too looked for a solution for this a while back and found literally nothing despite my hopes of finding a hidden option within Visual Studio.
It's only a little time taken from you though, so you should be alright.
I imagine this question has been asked and answered, but I cannot find it.
I wanted to make a simple GUI to interface to a windows 7 command. I usually use Wx, but since this was to be a windows-only thing, I decided to see if I could whip it out real fast using Visual C# 2010 Express, which I had never used before.
Things started off just great. I created a form, put a few buttons and text boxes and such on it, and hit Debug. It came up and ran just like that. No muss, no fuss. So I then designed the form just the way I wanted it, renamed the controls from "Button1" and so forth to meaningful names. But now it's a mess. By clicking around, I discovered that VC# had auto-generated two files called Form1.cs and Form1.Designer.cs. The later contains the bindings between functions and the events generated from user-clicks etc., and the former contains no-op code for those functions, for me to complete.
Problem is, the names are all still the original "Button1" and so forth, not the new ones, and the new controls I added after running the first time do not appear at all.
I want it to regenerate all that stuff afresh from the finished form. How to?
You probably don't have an actual problem, unless you edited something within Form1.Designer.cs. Provided you left that file alone, things should just work.
Whenever you double-click on a button, or use the events interface to create event handlers, the handlers are created with the following pattern:
ObjectName_EventName()
So, for example:
Button1_Click()
If you later change the name of Button1, the event handler's name is not changed, too. But it is still attached to the proper event, again - assuming you did not edit anything in Form1.Designer.cs
If you look (but don't touch!) inside Form1.Designer.cs, you will probably find something similar to:
MyNewButtonName.Click += Button1_Click;
(I don't recall the exact syntax the editor uses for wiring up event handlers; the principle is you should see your new button name being attached to the old handler name)
In work and in home I have VS2010 installed. But in work I have this one cool feature. On the code behind file I have two drop downs. When I select some object in the left one lets say a testButton or Default2 (a page class), on the right one I get all available events for that object and when I select an event Visual Studio autogenerates it in my code-behind file. In my home VS I actually have does 2 drop downs but they work different. I have available objects on the right one but when I select for example the testButton it shows me the aspx page and points this button :/ Should I set sommething in the VS configuration or maybe in work I have some addon which I'm not aware of? Any ideas?
This is not a VB-exclusive feature.
What you're looking for is called a navigation bar. In Visual Studio options, open Text Editor → C# → General, and you'll see an option called Navigation Bar. Enable it and click OK.
However, I believe this bar works a bit differently in VB and in C#. In C#, it only lists the existing classes and their methods; in VB, it will list all your controls and their events even if those don't exist yet.
Ok I think I've found the answer. It seems that this feature is only available when the current file is in VB.Net. In my opinion this suks :/
You need to go the design view, in the Properties box, click on Events (lighting bolt) and double click on the events you want to code behind:
(source: byte.net)
#shin is correct, this is a VB.NET only feature; Microsoft only had feedback reports dating back to 2004 mentioning this feature, so I have opened a new bug request with Microsoft regarding this; and also added feedback to Visual Studios account on UserVoice...
https://connect.microsoft.com/VisualStudio/feedback/details/688175/vs2010-c-add-page-event-handlers-to-asp-net-using-codebehind-navigation-bar-the-same-way-as-in-vb-net
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2244558-allow-c-to-add-event-handlers-to-classes-using-co
I encourage everyone who this issue effects to go and vote up & confirm this issue with them.
I dislike that C# doesn't provide such a useful time-saving function.
Up to Visual Studio 2010, only Vb.net has this feature: on code-behind page, the code panel upper-left drop down shows a control's name, and the right drop down shows this control's available events. When clicking this event we can get the code-block for this event. This feature is not available in C#.
Without above feature, we can still get a control's available events for both C# and Vb.net: We must select the control on the aspx page and choose the design view at the lower left corner, then on the Properties panel click the Event button (the lighting sign), then available actions will be shown, double-click the name of the event you want, the event code will be generated in code-behind.
It is most certainly is a VB only feature and has been reported on numerous occassions to Microsoft.
It is possible to see all the available Events in C# & Asp.net too, but not inside code window as possible in VB. But you can see all Events of any selected Control in its Property Window. Open Properties, then Click Events.
This and the feature to generate event handlers without having to switch to Design view for C# is finally coming in Visual Studio 2012. It was about time.
Even the 2012 feature is not enough. You still have to guess for Page level events (Init, PreRender, etc) and also files that haven't already been filled out for you like Global.asax, which depending on the template you started with may or may not have all the event handlers already specified.
Agreed that Event Handlers is one of the things VB has for years and years and years handled way better than C#. I can't count the number of times I've had to remind a fellow C# developer that some events do, in fact, exist.