Best Of
Re: Is it possible to call c# Method from js?
- In C# create invisible button with
onClick
handler. - In JavaScript set button text to the data you would like to pass to C# and initiate button click.
string UrlSweetAlert2Js = "https://cdn.jsdelivr.net/npm/sweetalert2@11"; Util.HtmlHead.AddScriptFromUri(UrlSweetAlert2Js); // Create button for receiving callback fron JavaScript. var callbackButton = new LINQPad.Controls.Button ("", onClick: btn => btn.Text.Dump()) { Visible = false }.Dump(); var js = @$" Swal.fire({{ title: 'Do you want to save the changes ? ', showDenyButton: true, showCancelButton: true, confirmButtonText: 'Save', denyButtonText: `Don't save` }}).then((result) => {{ // Get callback button ID. let b = document.getElementById('{callbackButton.HtmlElement.ID}'); if (result.isConfirmed) {{ Swal.fire('Saved!', '', 'success'); // Update button text. b.textContent = '{nameof(Saved.Yes)}'; }} else if (result.isDenied) {{ Swal.fire('Changes are not saved', '', 'info'); // Update button text. b.textContent = '{nameof(Saved.No)}'; }} else {{ // Update button text. b.textContent = '{nameof(Saved.Cancel)}'; }} // Do callback back to C#. b.click(); }}); "; Util.InvokeScript(false, "eval", js); enum Saved { Yes, No, Cancel }
Re: LINQPad.Controls Event sender got null
var button = new LINQPad.Controls.Button("Copy").Dump(); button.Click += (sender, e) => { var buttonSender = sender.GetType().Dump(); };
LINQPad.Controls.Core.HtmlElement
Re: Trigger TextBox TextInput event not work
I give up and find another way
I achieve by InvokeScript with JS dispatchEvent
public class SV_InvokeScript { public static void TriggerById_Input(string id) => TriggerEventById(id, OpEvent.input); public static void TriggerById_Click(string id) => TriggerEventById(id, OpEvent.click) ; public static void TriggerEventById(string id, OpEvent eventName) { new SV_SweetAlert(); Util.InvokeScript(false, "eval", @$" try {{ var target = document.getElementById('{id}'); if(target === null) throw new Error('not found id : {id} '); target.dispatchEvent(new Event('{eventName.ToString()}')); }} catch (error) {{ swal('JS error!', error.message + error.stack, 'error'); }} "); } public enum OpEvent { input, click, } }
Re: Benchmark stuck on "Waiting for first iteration to complete..."
I came across this error message and the reason was because BenchMark DotNet requires a parameterless constructor which is missing for connections using a DBContext in a custom assembly.
In my case I could solve it by adding my own like
public UserQuery() : base (LINQPad.Util.CurrentCxString) {}
See https://forum.linqpad.net/discussion/comment/8382 for a similar issue.
Re: AAD Authentication
Thank you for your hint. The connection string works now, after several adaptations.
Re: Any interest to support C# script ".csx" file extension?
Another +1 for basic csx support.
When I open a csx file in LinqPad it doesn't seem to understand/convert the #r style package references and errors with CS7011 #r is only allowed in scripts (of course please let me know if I'm missing an option in LinqPad that supports this!).
I am not a hardcore dotnet-script/csx user so I absolutely don't know everything supported by csx, all the potential complications and various expectations different users might have - but using LinqPad to seamlessly develop csx files that I can then run on any machine/OS regardless of whether LinqPad is installed would be great!
But for me the there would be huge value in Linqpad handling #r package references on opening a csx file, and offering 'save as' for 'C# Statement(s)' into csx (writing package references in #r style and including using statements).
I have voted and commented on UserVoice since this might fairly be more of a feature request rather than a discussion at this point...
Re: Any interest to support C# script ".csx" file extension?
+1 on supporting csx files in Linqpad
Re: Allow more than 10 files to be shown in recent files list.
Good idea. I'll add this to the next build.
Re: LINQPad for macOS: First public preview!
Most shortcuts that use the Alt key in LINQPad for Windows use Control-Command under macOS. You can change this to use the Option key in Settings/Keyboard - this is recommended if you don't use the Option key to generate special characters.
Set results window default size and position
Hi,
Is there a way to control the monitor and position of the results window when undocked?
I have two monitors and usually have LINQPad(5/7) snapped to the right-hand half of the right-hand monitor. When undocking, I almost always want the window to fill the left-hand half of the the same right-hand monitor, and so I end up manually resizing and moving the window from the default left-hand monitor every time.
My ideal would be to be able to position the results window and then have a button available in that window to set the current size and position as the default for that monitor setup. (ie there might be different configs for 1,2,3... monitors).
For the cherry on top, being able to set this at both app and query (override) levels would be helpful too as I have many queries that work in conjunction with other open apps.
Is anything to set the default position currently? I don't think so but I thought I'd check / register interest.
Best regards
John