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?
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.
Member
29 Points
319 Posts
Hide components is there a Me.Visible equivalent for a Blazor controls
Jun 27, 2020 08:21 PM|BigMeat|LINK
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 advance
All-Star
194857 Points
28100 Posts
Moderator
Re: Hide components is there a Me.Visible equivalent for a Blazor controls
Jun 29, 2020 07:53 AM|Mikesdotnetting|LINK
The most obvious way is:
@if(condition)
{
<MyComponent />
}
Member
29 Points
319 Posts
Re: Hide components is there a Me.Visible equivalent for a Blazor controls
Jun 29, 2020 08:39 AM|BigMeat|LINK
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
All-Star
58464 Points
15785 Posts
Re: Hide components is there a Me.Visible equivalent for a Blazor controls
Jun 29, 2020 03:57 PM|bruce (sqlwork.com)|LINK
just add a property to the component that you can set, and put the if inside.
Member
29 Points
319 Posts
Re: Hide components is there a Me.Visible equivalent for a Blazor controls
Jun 29, 2020 04:05 PM|BigMeat|LINK
Bruce, thanks ever so much.... why didnt I think of that!
Such a simple but effective approach
Thanks again