Bold BI®Unlock stunning dashboards with Bold BI®: 35+ widgets, 150+ data sources, AI agent & more. Try it for free!
I am trying to pass args as well as a parameter as async with onchange for a checkbox. I am getting this runtime error "Unhandled exception rendering component: Failed to execute 'setAttribute' on 'Element': '@onchange(async' is not a valid attribute name". Thanks in advance.
<SfCheckBox Disabled="@AdminIsDisabled" @bind-Checked="userDetails.AdminSelected" ID="checkboxAdmin" @onchange(async (Enums.Role.Admin, args) => await OnChangeRole())></SfCheckBox>
@code{
private async Task OnChangeRole(Enums.Role role, ChangeEventArgs args)
{
bool isSelected = Convert.ToBoolean(args.Value);
if (isSelected)
{
await SetRole((int)role, isSelected, true, true, false);
}
else
{
isSelected = true;
}
}
}
Hi David,
We have validated your reported query and prepared the sample code snippet based on your provided code snippet. Please pass arguments like below highlighted line.
@using Syncfusion.Blazor.Buttons
<SfCheckBox Disabled="@AdminIsDisabled" @bind-Checked="userDetails" ID="checkboxAdmin" @onchange="e => OnChangeRole(Dummy, e)"></SfCheckBox>
@code{ private bool AdminIsDisabled = false; private bool userDetails = true; private Enums Dummy = new Enums { Role = "Admin" };
private async Task OnChangeRole( Enums role, ChangeEventArgs args) {
}
public class Enums { public string Role { get; set; } } } |
Could you please check the above code and get back to us, if you need any further assistance on this.
Regards,
YuvanShankar A
That worked. Thank you so much. Quick question. I am knew to working with Blazor. Even though there is no await on the SfCheckBox this will still be one async?
I figured out how to do this asynchronously. Adding it in case it helps others.
<SfCheckBox Disabled="@AdminIsDisabled" @bind-Checked="userDetails.AdminSelected" ID="checkboxAdmin" @onchange="@(async (args) => await OnChangeRole(Enums.Role.Admin, args))"></SfCheckBox>
And the method would look the same as above
private async Task OnChangeRole(UM.Common.Enums.Role role, ChangeEventArgs args)
{
}
Hi David,
Thanks for your update. Please let us know if you have any other queries.
Regards,
YuvanShankar A