event-handling

Should I always disconnect event handlers in the Dispose method?

非 Y 不嫁゛ 提交于 2019-11-27 04:44:25
I'm working in C# and my workplace has some code standards. One of them is that each event handler we connect (such as KeyDown ) must be disconnected in the Dispose method. Is there any good reason for that? Unless you expect the publisher of the event to outlive the subscriber, there's no reason to remove the event handler, no. This is one of those topics where folk lore has grown up. You really just need to think about it in normal terms: the publisher (e.g. the button) has a reference to the subscriber. If both the publisher and the subscriber will be eligible for garbage collection at the

jquery mousewheel: detecting when the wheel stops?

天大地大妈咪最大 提交于 2019-11-27 04:37:24
I'm using Jquery mousewheel plugin and I would like like to be able to detect when the user has finished using the wheel. Similar functionality as the stop: event in the draggable stuff. Can somebody point me to the right direction? There's no "stop" event here really - you get an event when you do scroll, so every time a mousewheel event happens the event is triggered...when there's nothing you'll get no events and your handler won't be firing. You ca however detect when the user hasn't used it in say 250ms, like this: $("#myElem").mousewheel(function() { clearTimeout($.data(this, 'timer'));

How to use a function that takes arguments with jQuery's change() method?

醉酒当歌 提交于 2019-11-27 04:26:36
问题 I'm using jQuery version 1.5. I am looking at jQuery's change() function and specifically at this bit: .change( [ eventData ], handler(eventObject) ) eventData: A map of data that will be passed to the event handler. handler(eventObject): A function to execute each time the event is triggered. What exactly is a "map of data" in JavaScript? How can I use the following test function as an event handler? var myHandler = function(msg){alert(msg);}; I've tried this: $("select#test").change(["ok"],

Fake “click” to activate an onclick method

瘦欲@ 提交于 2019-11-27 04:20:45
I have an element with an onclick method. I would like to activate that method (or: fake a click on this element) within another function. Is this possible? If you're using JQuery you can do: $('#elementid').click(); Once you have selected an element you can call click() document.getElementById('link').click(); see: https://developer.mozilla.org/En/DOM/Element.click I don't remember if this works on IE, but it should. I don't have a windows machine nearby. I could be misinterpreting your question, but, yes, this is possible. The way that I would go about doing it is this: var oElement =

Handling end process of a windows app

余生长醉 提交于 2019-11-27 04:00:06
问题 Is it possible to capture the task manager end process of a windows application within the same windows application itself? I am using a C# 2.0 win app and I would like to do some database processing (change a flag from 'Y' to 'N' in the DB) when an end process happens. 回答1: No, it is not possible to hook the operating system's decision to end a process. Note, this is not done by task manger, ending a process is the responsibility of the kernel. You will need to do two things here: Connect

How to subscribe to other class' events in C#?

我们两清 提交于 2019-11-27 03:59:53
问题 A simple scenario: a custom class that raises an event. I wish to consume this event inside a form and react to it. How do I do that? Note that the form and custom class are separate classes. 回答1: public class EventThrower { public delegate void EventHandler(object sender, EventArgs args) ; public event EventHandler ThrowEvent = delegate{}; public void SomethingHappened() => ThrowEvent(this, new EventArgs()); } public class EventSubscriber { private EventThrower _Thrower; public

How do you add marker to map using leaflet map.on('click', function) event handler

孤街浪徒 提交于 2019-11-27 03:54:36
问题 I'm trying to use an event handler to add a marker to the map. I can manage this with a callback function, but not when I separate the function from the event handler. Callback (http://fiddle.jshell.net/rhewitt/U6Gaa/7/): map.on('click', function(e){ var marker = new L.marker(e.latlng).addTo(map); }); Separate function (http://jsfiddle.net/rhewitt/U6Gaa/6/): function newMarker(e){ var marker = new L.marker(e.latlng).addTo(map); } 回答1: in your fiddle code, your function is in the wrong scope.

How to raise an event from a SWF in a SWFLoader to a parent Flex application?

大城市里の小女人 提交于 2019-11-27 03:40:38
问题 How can I raise an event from a SWF file loaded into a Flex application (using SWFLoader)? I want to be able to detect a) when a button is pressed b) when the animation ends 回答1: You'll need to do 2 things: Dispatch an event from the loaded swf. Make sure the event bubbles if you sent it from nested views. Bubbling can be set through the bubbles property of the event. Listen to the event from your main application. I think you should be able to do that on the content property of the SWFLoader

Reading the selected value from asp:RadioButtonList using jQuery

时光毁灭记忆、已成空白 提交于 2019-11-27 03:38:31
I've got code similar to the following... <p><label>Do you have buffet facilities?</label> <asp:RadioButtonList ID="blnBuffetMealFacilities:chk" runat="server"> <asp:ListItem Text="Yes" Value="1"></asp:ListItem> <asp:ListItem Text="No" Value="0"></asp:ListItem> </asp:RadioButtonList></p> <div id="HasBuffet"> <p><label>What is the capacity for the buffet?</label> <asp:RadioButtonList ID="radBuffetCapacity" runat="server"> <asp:ListItem Text="Suitable for upto 30 guests" value="0 to 30"></asp:ListItem> <asp:ListItem Text="Suitable for upto 50 guests" value="30 to 50"></asp:ListItem> <asp

jQuery .on(); vs JavaScript .addEventListener();

戏子无情 提交于 2019-11-27 03:23:19
Can someone explain me why is there a difference in the order in which the event handlers are being executed depending on how they have been attached? In the example below I'm using the .on() and .addEventListener() methods to handle a specific event on different DOM elements. jsfiddle : http://jsfiddle.net/etsS2/ I thought that in this particular example the order in which the event handlers are going to be executed will depend on the event-bubbling - so starting from the original event target and moving up to the document element. document.getElementById('outer').addEventListener('mouseup',