event-handling

Best way to get the name of a button that called an event?

☆樱花仙子☆ 提交于 2019-11-30 15:32:29
In the following code (inspired by this snippet), I use a single event handler buttonClick to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to add 50 buttons instead of 2, this method could become cumbersome. Is there a better way to do this? import wx class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, 'wxBitmapButton', pos=(300, 150), size=(300, 350)) self.panel1 = wx.Panel(self, -1) self.button1 = wx.Button(self.panel1, id=-1, pos=(10, 20), size = (20,20)) self.button1

dynamically created list of link buttons, link buttons not posting back

ぐ巨炮叔叔 提交于 2019-11-30 15:21:51
Hi I am dynamically creating link buttons in a 'ul li' list. I am then trying to tie each link button to a click event where i set a label to the text of the link button clicked. however the event that should fire doesnt get fired? if (!Page.IsPostBack) { int listItemIds = 0; foreach (Node productcolour in product.Children) { HtmlGenericControl li = new HtmlGenericControl("li"); LinkButton lnk = new LinkButton(); lnk.ID = "lnk" + listItemIds; lnk.Text = productcolour.Name; lnk.Click += new EventHandler(Clicked); //lnk.Command += new CommandEventHandler(lnkColourAlternative_Click); //lnk.Click

How do you make an event listener that detects if a boolean variable becomes true?

荒凉一梦 提交于 2019-11-30 14:06:50
问题 For example, I have var menu_ready = false; . I have an ajax function that sets menu_ready to true when the ajax stuff is done: //set up event listener here $(...).load(..., function() { ... menu_ready = true; } How do I set up an event listener that waits for menu_ready to be true? 回答1: One way is continual polling: function checkMenu() { if (!menu_ready) { setTimeout("checkMenu();", 1000); return; } else { // menu_ready is true, so do what you need to do here. } } and... <body onload=

Elegant way to prevent circular events in MVC?

雨燕双飞 提交于 2019-11-30 14:05:35
The question, in brief: In MVC, how do you distinguish between a checkbox click (or a selectbox or listbox change) from a human meaning "Controller, modify the model", and a checkbox click (or a selectbox or listbox change) from the Controller meaning "I'm updating the view because the model has changed"? The example: I have a JS app (all one big HTML+JS page; there's a server behind it, and AJAX going on, but it's not important to the example) which has the notion of "Vertices" connected by "Edges". The UI lets you add and remove Vertices on a map, and enable or disable Edges between pairs of

How can I know if a .net event is already handled?

孤街浪徒 提交于 2019-11-30 13:54:42
问题 I've written some code to handle an event as follows: AddHandler myObject.myEvent, AddressOf myFunction It seemed that everything was working at first, but when I ran the debugger, I discovered that oftentimes, myFunction would run several times each time myObject.myEvent fired. I figured out that I had allowed the code to add the event handler to run more than once, resulting in this behavior. Is there a way I can do something like this? If myObject.myEvent is not handled Then AddHandler

How to attach event handler to an event using reflection?

前提是你 提交于 2019-11-30 13:50:50
I know about EventInfo.AddEventHandler(...) method which can be used to attach handler to an event. But what should be done if i can not even define proper signature of the event handler, as in, i don't even have reference to the event args expected by the handler? I will explain the problem with the proper code. // Scenario when I have everything available in my solution, Zero Reflection Scenario. internal class SendCommentsManager { public void Customize(IRFQWindowManager rfqWindowManager) { rfqWindowManager.SendComment += HandleRfqSendComment; } private void HandleRfqSendComment(object

Action<object, EventArgs> could not be casted to EventHandler?

你。 提交于 2019-11-30 12:30:46
问题 I was wiring up an event to use a lambda which needed to remove itself after triggering. I couldn't do it by inlining the lambda to the += event (no accessable variable to use to remove the event) so i set up an Action<object, EventArgs> variable and moved the lambda there. The main error was that it could not convert an Action<object, EventArgs> to an EventHandler. I thought lambda expressions were implicitly convertable to event handlers, why doesn't this work? 回答1: Lambdas are implicitly

Get select element value on event using pure JavaScript

半腔热情 提交于 2019-11-30 12:09:10
I want to get the value of a select element when the select element is clicked! I want to do it without an onchange attribute in the HTML. I would like to achieve this without jQuery. I don't want to include a jQuery framework into this website when this tiny script is the only thing I need. var select_element = document.getElementById('product-form-user-enquiry-type'); select_element.onchange = function(e){ if (!e) var e = window.event; var svalue = select_element.value; alert( svalue ); } if ( select_element.captureEvents ){ select_element.captureEvents(Event.CHANGE); } The select_element

Why is console.log an empty function on some sites in Chrome?

三世轮回 提交于 2019-11-30 11:50:05
Go to Twitter's login page and type the following in the console: window.addEventListener('keypress', function(e){console.log('hello')}, true) (NOTE: how the third parameter is set to true which enables event capture. This causes events to be intercepted first by the window before being consumed by a child element.) Try pressing some keys. Notice how hello isn't output to the console. Adding an event listener for keydown or keyup doesn't change anything. hello will get output on most websites, but not on sites like Twitter or Gmail. Why? What's stopping the event listener? EDIT: Seems to work

How to prevent calling of en event handler twice on fast clicks?

房东的猫 提交于 2019-11-30 11:30:14
There is a button and when user clicks on button, some data is saved to back-end. Issue is when user clicks on button very quickly, event handler is getting executed multiple times. This is the code var x = 1; $('#button').click(function() { // Do something // Save some data on network x++; console.log(x); }); I want this handler to get executed when user clicks on button just once. Even In case of double or tripple click, this should get executed only once. I just want to avoid quick clicks, this handler can get executed again ofcourse I have multiple solutions in my mind like Define a global