diff --git a/knowledge-base/dockmanager-reset-state.md b/knowledge-base/dockmanager-reset-state.md new file mode 100644 index 000000000..8ee241fb3 --- /dev/null +++ b/knowledge-base/dockmanager-reset-state.md @@ -0,0 +1,134 @@ +--- +title: Reset DockManager State on Button Click in Blazor +description: Learn how to reset the DockManager state in Blazor using a button click and save the default state after the initial render. +type: how-to +page_title: How to Reset DockManager State Dynamically in Blazor +meta_title: Reset DockManager State Dynamically in Blazor +slug: dockmanager-kb-reset-state +tags: dockmanager, blazor, state +res_type: kb +ticketid: 1691957 +--- + +## Environment + + + + + + + +
ProductDockManager for Blazor
+ +## Description + +I want to reset the [DockManager state](slug:dockmanager-state) on a button click. The DockManager currently only resets by reloading the page. I need a solution to reset its state dynamically. + +This knowledge base article also answers the following questions: +- How to reset DockManager layout to its default state? +- How to refresh DockManager without reloading the page? +- How to implement a button to reset DockManager panes? + +## Solution + +To reset the DockManager state dynamically on a button click: + +1. Capture and save the default DockManager state in the [`OnAfterRenderAsync`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.componentbase.onafterrenderasync?view=aspnetcore-9.0) lifecycle method. + +2. Restore the previously saved default state when the button is clicked. + +>caption Reset the DockManager layout to its default state + +````RAZOR +Change something in the DockManager (move, resize, or close panes). Đ¢hen click +Reset Dock State + + + + + + +
    +
  • Fix login bug
  • +
  • Implement dark mode
  • +
  • Refactor API requests
  • +
+
+
+ + +

Upcoming Meetings:

+
    +
  • UI Review - Feb 10
  • +
  • Code Freeze - Feb 15
  • +
  • Final Release - Mar 1
  • +
+
+
+ + +

User A updated Task 1

+

User B commented on Task 2

+

New PR merged for Feature X

+
+
+ + + + +

New messages from Sarah

+

Server maintenance scheduled for Sunday

+
+
+ + +

Enable email notifications

+

Change password

+
+
+
+
+
+
+
+ + + + + +

Live chat with team members

+
+
+ + +

Logs and debugging tools

+
+
+
+
+
+
+ +@code { + private TelerikDockManager? DockManagerRef { get; set; } + private DockManagerState? DefaultState { get; set; } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + DefaultState = DockManagerRef?.GetState(); + } + } + private void ResetDockState() + { + DockManagerRef?.SetState(DefaultState); + } +} +```` + +## See Also + +- [DockManager Overview](slug:dockmanager-overview) +- [DockManager State](slug:dockmanager-state)