Skip to content

Commit f4f82d6

Browse files
kb(common): Panel equivalent
1 parent c874797 commit f4f82d6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Panel Control
3+
description: How to use a control like a Panel from WebForms in Blazor
4+
type: how-to
5+
page_title: Panel Control Equivalent from WebForms
6+
slug: common-kb-panel-control
7+
position:
8+
tags:
9+
ticketid: 1503388
10+
res_type: kb
11+
---
12+
13+
## Environment
14+
<table>
15+
<tbody>
16+
</tbody>
17+
</table>
18+
19+
20+
## Description
21+
Is there a good equivalent in your control set or plans for new controls as a replacement for the Web Forms Panel control? We are trying to replicate UI that we had in our Web Forms project and we cannot find a good replacement for a panel.
22+
23+
I often have the situation that i have some controls (Textboxes, DropDowns,...). In Webforms i used a panel or AjaxPanel for example to set all of them invisible/visible. I am missing such a control in Blazor UI.
24+
25+
## Solution
26+
The Panel control in WebForms renders as a simple `<div>`, so this is what you could use to replace it in any razor-based solution (be that blazor, mvc, razor pages). You can set things like `class` or `tabIndex` to it for styling and other functionality.
27+
28+
Instead of setting the `Visible` property of a component/panel/control to toggle its visibility, you can toggle its CSS `display` property, or you just wrap the content you want to remove in a conditional `if`-block.
29+
30+
Depending on your needs, you might not even need a top-level element anymore, or you could use a different element (such as a `<fieldset>`). You could even wrap the desired logic inside your own component and provide a `Visible` parameter to it which will toggle the contents with an if-block. The razor syntax allows full flexibility in the way you approach this.
31+
32+
>caption Example of Panel-like Visibility toggle and appearance styling through a CSS class
33+
34+
````CSHTML
35+
@if (SpecialPortionVisible)
36+
{
37+
<div class="alert alert-success">this here is the special content</div>
38+
}
39+
else
40+
{
41+
<div class="alert alert-info">you can even do if-else checks easily, but you do not have to</div>
42+
}
43+
44+
<button @onclick="@( () => SpecialPortionVisible = !SpecialPortionVisible )">toggle content</button>
45+
46+
47+
@code{
48+
bool SpecialPortionVisible { get; set; } = true;
49+
}
50+
````
51+
52+

0 commit comments

Comments
 (0)