event-handling

Difference between assigning event handler to method with and without parentheses

柔情痞子 提交于 2019-12-02 04:00:33
问题 Assuming you have the following: function doStuff() { //code } What is the the difference between the 2 statements ? window.onload = doStuff; window.onload = doStuff(); Both statements immediately called the method, but if I used the first statement, I could treat onload as a function pointer to "doStuff" and just call the method again using: onload(); Is this the only difference, and in general, is this all guaranteed behavior for event handlers ? 回答1: You're actually a bit off in your

Invoke ASP.NET TextChanged event from JavaScript using __doPostBack

馋奶兔 提交于 2019-12-02 03:53:32
Like many others, I'm trying to invoke a .NET control's server-side event from JavaScript. Specifically, I want to fire the TextChanged event on a TextBox named txtSearch . Therefore, I'm looking to reach the following event from client-side: protected void txtSearch_TextChanged(object sender, EventArgs e) Having read many answers on SO (for example here and here ) I have the following JavaScript: __doPostBack('ctl00$ctl00$Container$Main$txtSearch', 'TextChanged'); But the server-side event never fires. I've tried numerous permutations: with the AutoPostBack true and false, with and without

Clarifications regarding weak references in actionscript listeners

倾然丶 夕夏残阳落幕 提交于 2019-12-02 03:41:28
I understand how weak references work, but I am bit confused regarding it's use in actionscript event listeners. Consider the example below: public class Rectangle extends MovieClip { public function Rectangle() { var screen:Shape=new Shape(); screen.addEventListener(MouseEvent.MOUSE_OUT, new Foo().listen, false, 0, true); addChild(screen); } } public class Foo extends MovieClip { public function listen(e:MouseEvent):void { trace("tracing"); } } Now here, since there is only a weak reference to Foo, would not the event listener Foo be garbage collected if and when the garbage collector runs

jquery on('click') handler for multiple elements referenced by vars

若如初见. 提交于 2019-12-02 03:29:09
问题 N.B. I'm aware that I add ids and combine these in a selector e.g. "#myDiv1,#myDiv2" so please refrain from suggesting this as it does not relate to my question. Is there a way to 'chain' the vars below together in one on() declaration maybe as an array or something? var myDiv1 = $('<div>Something here</div>'); var myDiv2 = $('<div>Something else here</div>'); myDiv1.on('click', function(){ doSomething();}); myDiv2.on('click', function(){ doSomething();}); I have a bunch of vars that I need

Add completion handler to presentViewControllerAsSheet(NSViewController)?

孤者浪人 提交于 2019-12-02 02:35:48
I am attempting to present a sheet configuration view ( AddSoundEffect ) for my main window/view controller (I'm using storyboards), and when the configuration view controller is dismissed, take the values entered in the AddSoundEffect view and pass that back to the main view. My current code in the main view controller: presentViewControllerAsSheet(self.storyboard!.instantiateControllerWithIdentifier("AddSoundEffect") as! AddSoundViewController And in the AddSoundViewController.swift file, the code to dismiss it is: self.dismissViewController(self) To pass the data, I have a class-independent

Difference between assigning event handler to method with and without parentheses

扶醉桌前 提交于 2019-12-02 01:45:44
Assuming you have the following: function doStuff() { //code } What is the the difference between the 2 statements ? window.onload = doStuff; window.onload = doStuff(); Both statements immediately called the method, but if I used the first statement, I could treat onload as a function pointer to "doStuff" and just call the method again using: onload(); Is this the only difference, and in general, is this all guaranteed behavior for event handlers ? You're actually a bit off in your understanding. window.onload = doStuff; means that when the onload event is triggered, the doStuff function will

WPF EventHandler fired on the wrong Element

笑着哭i 提交于 2019-12-02 01:44:35
I am puzzled by this: I have made a very simple example: MainWindow.xaml: <Window x:Class="Test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Style TargetType="RichTextBox"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="RichTextBox"> <Grid Height="100" Width="200"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Label Background="Blue" Grid.Row="0">Label</Label> <Border PreviewMouseDown

How to unit test (in C#) that a button is clicked?

a 夏天 提交于 2019-12-02 01:35:25
I have a user control that has button whose click event handler contains the core logic. I want to test this button click handler. This handler function calls a public function of another user control (which resides in separate C# project) which ultimately calls public function of a reference assembly. Can anyone please tell me - how will be the unit test for such a handler? You can write a method that programmatically raises the Click event and call that from your unit test. Edit: Ah, this actually exists already: http://msdn.microsoft.com/en-us/library/hkkb40tf(VS.90).aspx In unit testing,

jquery on('click') handler for multiple elements referenced by vars

*爱你&永不变心* 提交于 2019-12-02 01:33:09
N.B. I'm aware that I add ids and combine these in a selector e.g. "#myDiv1,#myDiv2" so please refrain from suggesting this as it does not relate to my question. Is there a way to 'chain' the vars below together in one on() declaration maybe as an array or something? var myDiv1 = $('<div>Something here</div>'); var myDiv2 = $('<div>Something else here</div>'); myDiv1.on('click', function(){ doSomething();}); myDiv2.on('click', function(){ doSomething();}); I have a bunch of vars that I need to do some broad tracking of mouse events and it feels messy setting them up individually like the above

Reserved function names in JavaScript

落花浮王杯 提交于 2019-12-02 01:23:52
After renaming my function the code stopped working. That new name scrollIntoView seems to be clashing with the element.scrollIntoView() method. <div onmousedown="scrollIntoView('id001')"/> function scrollIntoView(id) { alert(id); } I've created a simple test case https://jsfiddle.net/mgtn215y/ which has shown my function is simply ignored in favor of element.scrollIntoView() even it is not called on element attributes do not match The solution is obvious - to use a different function name. As this behavior is consistent across major browsers, I expect this is specified somewhere. However, I