I am using Blazor Server Pages. I need to reset to initial state of my component onClick
. I am using StateHasChanged()
which is called on clicking the update
button but does not reset the input
field to the initial Value.
My Component is given below.
@using DataAcessLibrary;
@using TableMaintenance.Models
@using TableMaintenance.Data;
@if (dr != null)
{
int count = 0;
<tr>
<td style="padding:0px"><button type="button" class="btn btn-link btn-sm" style="padding:0px" @onclick="@DeleteRow"><img src="/images/x-square.svg" /></button></td>
@foreach (var item in dr.ItemArray.Where((a, b) => ColDisplayIndex.Contains(b)))
{
string id = ColumnsList[ColDisplayIndex[count++]].ToString();
<td style="padding:0px;">
<DataRowInput Id="@id" Input=@(item.ToString()) OnChangeDropDown="@AddDropDownValue" OnChangeInput="@AddInputValue" />
</td>
<td>
<input type="text" />
</td>
}
<td style="padding:0px">
<button style="padding:3px;margin:0px" type="button" class="btn btn-light btn-sm" @onclick="@UpdateRow">update</button>
</td>
</tr>
}
My main goal is to reset DataRowInput
to its initial state on clicking update
button. I used input field for testing purpose and it does not reset too ( the input that I typed stays there even after clicking the update
button). I am new to Blazor and only way I could find to re-render a component is via StateHasChanged
. But this is not resetting values to their Initial state. The update method is given below
public void UpdateRow()
{
StateHasChanged();
}
Is this possible with StateHasChanged() or is there any other way?