Trigger TextBox TextInput event not work
var textbox = new TextBox().Dump(); textbox.Click += (s, e) => "Trigger Click".Dump(); textbox.TextInput += (s, e) => "Trigger TextInput".Dump(); // Trigger Click is work textbox.HtmlElement.InvokeMethod(false, "click"); // Trigger TextInput accour Exception textbox.HtmlElement.InvokeMethod(false, "textinput");
How to fix the code to trigger TextInput event
Comments
JavaScript
from exception:Element is
input
:Looks like there is a no such method for
input
.So is there any way to trigger TextInput event by code?
I'm a little confused by what you are trying to do.
The events are so you can run your own linqpad code when some javascript event occurs.
InvokeMethod is so you can run javascript code from your linq code.
But it looks like you are trying to invoke TextInput to call a javascript method simply so that the javascript method calls your own linqpad code - why not just call your linqpad code directly?
InvokeMethod
does not trigger event. It calls HTML element's function. In this case you are being lucky withclick
'cause it is a realHTMLElement
function. It is just a coincidence:click
function triggersclick
event.Could you elaborate on what you are trying to do?
I have a code to set textBox.Text = "something" , and I need to tirgger textBox's InputText at the same time
Workaround:
I used
Shift
+Alt
+R
to open in ILSpy and navigate implementation and it looks like a bug to me: JS event listener must be called on property change but it's not. I'll report it via LINQPad.input
event is not fired whenTextBox.Text
is changed:Implementation details:
I took a brief look at this last Friday, but didn't have much time to delve further. What I did observe is the event does trigger if you actually type into the TextBox. This makes sense when you consider the name of the event the code hooks into. "TextInput", not "TextChanged". Not sure this is a bug here, though perhaps a feature request.
The initial recommendation stands: If you changing the text in code, call the accompanying event code along with it (and consider writing a single method to do both).
@rorourke - that's correct. The
TextInput
event forwards the HTML element'sInput
event.Reliably responding to programmatic changes is tricky because the value can also be changed directly via JavaScript (bypassing LINQPad's C# wrapper):
https://stackoverflow.com/questions/55033836/how-do-you-listen-detect-changes-to-an-input-value-when-the-input-value-is-c
I give up and find another way
I achieve by InvokeScript with JS dispatchEvent
swal
should be included separately. I don't see a corresponding script tag.I implement in new SV_SweetAlert(); to using SweetAlert.js