Answered by:
Hide components is there a Me.Visible equivalent for a Blazor controls

Question
-
User-1482891610 posted
Hi
I am moving from Web Form to Blazor, i used a lot of Web User Controls in Web Forms.... I would encapsulate my logic in web user controls and then set various parameters on that user control. I see that Blazor Components work in a similar way which is great. I have created various Blazor Components, but if a certain condition is set which could be set by one of the parameters I dont want it to render the Blazor Component. In web forms I would use Me.Visible = False . This would prevent the control from render to the page. Does Blazor have anything similar?
Many thanks in advanceSaturday, June 27, 2020 8:21 PM
Answers
-
User-474980206 posted
just add a property to the component that you can set, and put the if inside.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 29, 2020 3:57 PM
All replies
-
User-821857111 posted
The most obvious way is:
@if(condition)
{
<MyComponent />
}
Monday, June 29, 2020 7:53 AM -
User-1482891610 posted
Hi Mike
Thanks for the response. I was tring to avoid that approach as I wanted to put the logic in the component. As I could end with lots of external if statements which would generate a lot of code.
Is there any other way?
Many thanks for all your support
Monday, June 29, 2020 8:39 AM -
User-474980206 posted
just add a property to the component that you can set, and put the if inside.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 29, 2020 3:57 PM -
User-1482891610 posted
Bruce, thanks ever so much.... why didnt I think of that!
Such a simple but effective approachThanks again
Monday, June 29, 2020 4:05 PM