TryParseValueFromString not firing for component inherited from InputBase<T> in SSR mode #60212
Closed
1 task done
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
question
Status: Resolved
Is there an existing issue for this?
Describe the bug
This is about using Blazor in SSR mode.
When creating a custom razor component that inherits from InputBase class, we are forced to implement the TryParseValueFromString function, since it is declared as abstract in the base class. Which is not a problem, but the TryParseValueFromString function never seem to be triggered. From code in InputBase it appears that TryParseValueFromString should be triggered when value is set to CurrentValueAsString. Hence in my component, I've bound to CurrentValueAsString, but that doesn't help. The companion method FormatValueAsString does get fired then the page is being rendered. But when the page is submitted, the TryParseValueFromString does not fire.
Elsewhere, people have suggested that @Bind=CurrentValue instead of CurrentValueAsString. That does not work either. With CurrentValue we even lose the call to FormatValueAsString.
I want to create an input component where both FormatValueAsString and TryParseValueFromString are triggered so that I can intercept the value on both ends (when value goes out to the browser, and when value comes back from the browser) and make some adjustments.
Expected Behavior
I would expect the TryParseValueFromString to be fired somewhere in the life-cycle, preferable before the razor page init, so that the Model.Greetings has a value that has been parse by our TryParseValueFromString function.
Steps To Reproduce
I have created a simple input component that inherits from InputBase. In this silly example, I want text value to always end with exclamation symbol.
On my razor page, this is how I used the new component:
When the form is rendered, the FormatValueAsString is fired as expected. But when the form is submitted, the TryParseValueFromString does not fire.
Sample code available here: https://github.com/anandgothe/SampleForTryParseValueFromString
Exceptions (if any)
No response
.NET Version
9.0.102
Anything else?
Sample code: https://github.com/anandgothe/SampleForTryParseValueFromString
The text was updated successfully, but these errors were encountered: