How to prevent OnSelectedItemChanged Call after Refresh
See original GitHub issueHi,
Each time the page is reloaded or clicked, the OnSelectedItemChanged for Select is executed. How can I prevent this? The same behavior can be seen on the Ant Blazor Page. The OnSelectedItemChanged should only be called, if I select an Item
<Select @bind-Value="@context.ColorState"
DefaultValue = "@context.ColorState"
TItemValue="ColorState"
TItem="ColorState"
OnSelectedItemChanged="(value)=>UpdateColor(context)">
<SelectOptions>
@foreach (ColorState color in Enum.GetValues(typeof(ColorState)))
{
<SelectOption TItemValue="ColorState" TItem="ColorState" Value="@color" />
}
</SelectOptions>
</Select>
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
How to avoid page refresh after selectedindexchanged of ...
I am using update panel and ASP drop down. When I select any value from a drop down list I load some data...
Read more >How to Keep selecteditem when refresh ItemSource.
Hello, I'm try to keep selecteditem in my GridControls after refresh grid itemsource property. I have two kinds of itemsource.
Read more >Avoid Prevent Page refresh PostBack after ...
Here Mudassar Khan has explained with an example, how to avoid (Prevent) Page refresh (reload) after SelectedIndexChanged is fired in ASP.
Read more >Select previously selected row after refresh in UI for WPF
Hello Vikas, I am attaching a sample application demonstrating how the SelectedItem property of RadGridView can be set. For this purpose, I have ......
Read more >How can I prevent SelectionChanged event for a ...
Actually, I have some method, and I called this method in Combobox Drop down event and that causing the item source to reset....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@anddrzejb
I agree with @minas15 , and this is not the only issue with
OnSelectedItemChanged
. When set theValue
programmatically,OnSelectedItemChanged
is not triggered.And I basicly agree with @susahin80 .
Microsoft suggests that paramter properties should only be set by binding values. However, it’s true that we don’t always follow this rule. I think we should act base on the source of
Value
when it changes. If theValue
is from the bindingValue
then we should not triggerValueChanged
, otherwise there will be an unnecessary rerendering.@anranruye thank you for sharing the issue. It was a worthwhile read. And I agree with your understanding of properties use when marked with
[Parameter]
attribute. Although I am not sure if the suggestion of forcing only{get;set;}
is entirely warranted. Of course, without understanding of possible underlying problems, it is a good solution, but in the hands of a programmer well versed in blazor internals, using setters (or getters) can help keeping the code cleaner & leaner.But now I can see that there was a misunderstanding (or at least I think there was). I was not referring to changing value of the child component (so the
[Parameter] Value {get;set;}
, I was rather referring to changing the parent’s variable that is bound toValue
parameter. But the more thought I gave to the issue, the more I think @susahin80 is actually correct.