Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
How to Pass a c# variable to javascript in Blazor Web Assembly

I am using Blazor Web assembly and the 3rd party component does not support @onitnput , @bind-value:event="oninput". To try and get around this I am attempting to use JS to trigger a c# function. (I have other stuff that is triggering the "onchange" on input so when you look at my example just think of it as oninput, and that is working).

Main issue: I need to pass a reference to the page into the method being called by onchange so that I can then call the c# method from JS but I can't get it to pass the parameter. Here is my markup

<RadzenHtmlEditor @bind-Value=@SurveyScriptNode.Script onchange="callCSharpMethodNoParams(@DotNetObjectReference.Create(this))" style="height: 500px; margin-bottom: 1rem; opacity: 1;" UploadUrl="upload/image" Paste=@OnPaste Execute=@OnExecute id="scriptBuilder_surveyScriptNode_ScriptEditor">

I also tried what was suggested Here but could not get it working either

<RadzenHtmlEditor @bind-Value=@SurveyScriptNode.Script onchange="callCSharpMethodNoParams(<%=DotNetObjectReference.Create(this)%>)" style="height: 500px; margin-bottom: 1rem; opacity: 1;" UploadUrl="upload/image" Paste=@OnPaste Execute=@OnExecute id="scriptBuilder_surveyScriptNode_ScriptEditor">

Is there any way to do this in Blazor?

Thank you for your time.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As a workaround I am doing this:

  • Hide a check box

  • Set a js oninput method on the desired control, this will call a js function that sets the hidden check box to true

  • Since the hidden checkbox can't @bind when JS updates the value and it will not update the value when calling StateHasChanged(), you need to implement a timer that uses JS interop to call a js function to return the value of the hidden check box to your c# code.

  • Set the value of the c# variable to the returned value of the previous step

  • Create another method in the c# that uses JS Interop to call the js function you use in your on input, call this method in the setter of the c# variable but make sure to only do it if the page is already initialized.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!