Keyboard Shortcuts Creating Event Methods in Visual c# - c#

i know there is a way to quickly create a an event handling method like onPaint onLoad etc. by typing a small amount of the method then using the tab key. but i am a lil rusty and cant remember how? can anyone shed some light? i am using Visual c# express 2010

I believe you are looking for code snippets: https://msdn.microsoft.com/en-us/library/z4c5cc9b(v=vs.90).aspx

In the design mode, when selecting particular control, you would double-click to create a new event handler (stub) for specific event. Here is more: Creating Event Handlers in Visual Studio

Related

How to get all events on Visual Studio 2017

I am trying to create a simple WebForm in Visual Studio 2017. I have a textbox and I have to catch "Leave" event on it, but these are the only events available:
I've been searching for similar questions and problems but I did not find any solutions.
There is no Leave event because ASP.NET runs on Server while the user's "leave" happens on the client. You could handle the blur event in JavaScript and then do a post back. Very nice solution is in this SO answer.
This is normal behavior, you're working with a System.Web.UI.WebControls.TextBox.
It doesn't have a Leave event since it's a Web UI control. If you want a Leave event, you'll have to use Javascript (note that this will be Client-Side).

Visual studio wpf events

I'm sure that since visual studio went free you've gotten lots of nooby questions, and I'm here to add onto that pile.
When I make a button in wpf I can't figure out how to get it to let me edit actions for button press. I know how to add events under the triggers tab however when I switch over into the MainWindoww.xaml.cs there isn't any code in it for that event. So what do I need to do in order to work with button events?
P.S I have visual studio 2013 community.
Here is a simple code snippet that will probably help. Assuming that you have a WPF button named btnControl in your XAML, you can add the following click event handle to the code behind (MainWindoww.xaml.cs) module:
btnControl.Click+=(s,e)=>
{
// put your click event proc code here
};
Note: you do not need to modify your XAML.
Hope this will help. Regards,

Moving asp.net team from VB.Net to C#, seems are we are missing something with wiring up events?

An asp.net (mostly webforms) team I work on has recently decided to make the move from vb.net to c#. The people who used to be on the team who couldn't read/write C# code well had since moved on, and each time we hired a new person it became more of a problem for us to be a vb.net shop.
I'll save the standard vb/c# language war stuff and just stick with the one thing that I ran into today.
With vb.net, when we want to handle some event from some object, we just pick the object out of the list in the upper left, pick the event out of the list on the upper right, and it creates the fully wired up event handler. It's also very clear that the method is an event handler due to the "Handles ... " at the end.
In the C# world, it seems we are left with a few poor options.
1) Manually wireup the event by typing the name of the event and event handler in the aspx markup. Like actually writing "OnLoad=SomeFunction" in the aspx. (EDIT: I didn't realize that his only applied to the form and not to any contained controls, so I guess this isn't really an option)
2) Using auto wireup events, and naming methods and signatures correctly so that they match up.
I'm hoping I'm missing some other much better option.
With these 2 options that I've seen so far:
1) we have to know the event names and event arguments. We can't just look down the list and be like "Oh good this has OnItemClick", I have to go research that in some control documentation. Likewise I'd have to go research the event args to find out that ItemClick needs a RadPanelBarEventArgs as the 2nd parameter. Wasted time.
2) I get no compile check on anything I'm doing with regard to connecting events. If I name the method signature wrong, or if I type it in wrong in the aspx page, everything will compile just fine until runtime when the mismatch will blow things up. (EDIT: what I mean is if I type onClick="ABC" and the event handler is really named "ABCD" this will not be caught at compile time. With VB, issues with renaming/mistyping event handler names are caught at compile time, because of the "Handles". Same goes for if I have onClick="ABC" and this controls onClick really needs a SpecialEventArgs but I accidentally use SomeRegularEventArgs)
I'm hoping we missed something and there is a better way to do this.
This is a known 'bug' or missing feature. See Visual studio 2010 showing available events from code behind
If you want to auto-generate events in C#:
Go to your aspx page in Design View.
Make sure the properties panel is visible
Either select a control with your mouse, or use the
dropdown under properties to select the control.
Move to the Events tab (the lightning bolt)
Find the event you want to wire up and either write in a name and hit Enter, leave it empty and hit Enter, or Double-click it.
It will create the event handler with all the
properties.
As for Number 2. Are you putting your code in a code-behind file? .aspx.cs?

How to help Intellisense so it lists event handlers in my aspx pages?

I've got a custom button control that handles an OnServerClick. My aspx dev's are asking me if it would be possible to influence Intellisense so it will give me all the possible event handlers for that page. Is this possible?
Basically I would like to have auto completion on my OnServerClick events in my ASPX pages (just like when I would have an enum).
Any idea?
It's not possible to get intellisense on server side events in the aspx.
It probably only works in the designer. When your dev's want to see the possible handlers, they can check out the designer and view the click eventhandlers in button properties / events / click.
Simply a limitation / bug / you name it of Visual Studio 2010 and lower.
But: maybe VS 2011 will make you happy! :
In VS 2011 Developer preview, markup intellisense for all ASP.NET
server-side events will show you list of exiting handlers and a value
called “Create New Event” . Which means you can attach the event
with some exiting event handler or select “create New event” to
generate an new handler with the right signature in the code-behind
file.
For more info and screenshots:
Server Side Event Handler Generation From ASP.NET Markup in Visual Studio 2011 Developer Preview

Visual Studio 2010 WinForms designer deletes code in unused event handlers

My VS2010 WinForms designer keeps doing strange thing.
Let's say I have a button and there's a method/handler assigned to the button's Click event. This method contains some code. Now if I want to stop using the method or just to use it somewhere else, I select the button and open its events list, where I unbind the method from the event.
The result is that the method stays but the inner code is gone.
Why? If it's supposed to be some kind of optimization, then I'm not interested.

Categories

Resources