Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a reference to a blazer control in code

Tags:

.net-5

blazor

How can I get a reference to a blazer control in code. I would like to change the control in code.

like image 952
Joe K Avatar asked Nov 01 '25 05:11

Joe K


1 Answers

You have to use @ref on component declaration.

At next step, you have to define a variable with component type.

Now, you can access the component with variable.

<InputText @ref="PersonalNameTextbox" ...

In @code or razor.cs, define a variable:

InputText PersonalNameTextbox;

Example of access the component in afterRender, you can access them:

protected async override Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
        PersonalNameTextbox.Value = "Untitled!";
    ...
}
like image 114
mRizvandi Avatar answered Nov 04 '25 08:11

mRizvandi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!