I have to click twice to fire an event - c#

I'm developing a windows form application in C# and (SOMETIME) every button in the form need to be clicked twice to fire an event.
Can anybody suggest a solution?
Best Regards,
BaDoOoReY

Its a win form application.
I think you have handled button_doubleClicked event instead of Button_Clicked event.
Please make sure that you handle Button_Clicked event.
If this is not the case then can you please share your code ??

You can create a puplic variable with 0 value.
When the user click the button for the first time you give the varriable value 1.
When the user click the button for the second time you give the varriable value 2.
and you make if statement to check if the varriable is equal 2, this mean that the button clicked twice, if true you can fire your event.
Also you can you use button double_cilck event.

I think roundtrip is not happening some times because of any ajax control or javascript.If you use any of these two please check this may stops events to fire server side some times.

Related

Make Button Ignore ENTER key pressed c#

im building a page using ASP.NET, however, the first element of my page is a Button and there are other elements below it, however, if the client types something and it shows a confirmation box, and he presses ENTER key, it activates the first button at the page.
I tried to change the tab order does not work.
sorry for noob question xD
Have you tried setting UseSubmitBehavior=False on the first button?
Don't handle the click event. Handle the MouseClick event instead. So whatever code is in click, simply move to the MouseClick event

C#.NET mnemonics unexpected behaviour

I have few buttons in my windows application which has mnemonics.Now if i press multiple keys the events of the button clicks gets fired as i have used mnemonics.
But the behaviour is not as expected,because second button event handler is getting executed before the first button event handler has finished its execution,and also i have written my code in such a way that in the event handler of first button i am disabling my second button,still the second button event handler is getting executed.The problem here is due to mnemonics.PLease suggest me a better way to handle mnemonics as soon as possible.
Thanks in advance.
If your logic is tied to your buttons, change that. Let your buttons merely manipulations an object that implements your logic. You can then check in this object whether the requested action is allowed (i.e. whether the previous operation has finished.
Alternatively you can just disable buttons when running and re-enable then when.finished.

C# - are there any events fired right after loading a form?

I want to give the user the option to use a tutorial, the first time he uses the program. I tried adding it in the Form.Load event, but the forms shows up after the Messageboxes have popped up.
That's why I would like to know, are there any events fired right after loading a form?
If not, is there a way to perform actions right after loading?
You should try the shown event, which fires after the form is shown for the first time.
Load happens before the form is shown.
You could try using the Shown event but that might be a bit early too based on what you are doing but it does occur after the Load.
If you have any controls on the page you could trigger it off the controls GotFocus event. Just make sure to put in checks to only do it once if using the GotFocus method.
MSDN Form.Shown
MSDN Control.GotFocus
MSDN Reference to order of events
System.Windows.Forms.Control.HandleCreated
System.Windows.Forms.Control.BindingContextChanged
System.Windows.Forms.Form.Load
System.Windows.Forms.Control.VisibleChanged
System.Windows.Forms.Form.Activated
System.Windows.Forms.Form.Shown
The Shown event should do this for you.

How to handle complete change of the Textbox in Windows Forms?

What event I should handle to react to the completed change of the TextBox (i.e. when the user is
finished editing the content of the TextBox)?
There are several methods that you can use: Leave event, or a manual "typing stopped" event.
The Leave method is the most straight forward way of doing it, although as the event name suggests, it only happens when they TextBox looses focus, not when the user stops typing.
The TypingStopped event is something you would need to create yourself, but the basic idea of it is a short duration timer (say 500ms, but you would need to test it), which you restart on every KeyDown event of the TextBox. The timer would fire its own event and disable itself if it ever hits the end of it's timeout.
Edit: Updated to Leave event as per Hans' recommendation.
The Leave event is generally a good one for processing user input (for validation for example) as they move on to another part of the form. Just make sure that the event fires if they go from the textbox to any other UI element on your form - you may need to force a focus on the new element.

Generating event on .cs page by double click on the design view of .aspx page

I am developing a web application in asp.net and c#, now in a particular aspx page whenever I doubleClick(design view) on a button or on a drop down list, instead of going to
public void btn_click event or DropDown_SelectedIndexChanged event, the cursor points to protected void Page_Load only. Strange!! any remedy?
Not a fix for your VS misbehaving, if it is doing so. But this will help you wire up your events and perhaps notice anomalous event assignments:
Select the control in question, right-click>Properties, switch to the 'events' tab (lightning bolt) and either enter the name of a method or simply double click the empty space to generate an event handler in your codebehind.
This is also where you will see if Page_Load is already, for whatever reason, assigned to the event you are having trouble with.
HTH
May be both your btn_click event and DropDown_SelectedIndexChanged event delegates have Page_Load as the method. Check your events tab for button and dropdown.
this happens to me when I have my project running in debug mode and forget to stop it before editing my code. Long shot, but sometimes the obvious things are the things we overlook :)

Categories