DwsPageBaseComponent
The DwsPageBaseComponent is a base component that provides a consistent layout and structure for your pages. Below are examples of how to use this component.
Interface Description DwsPageBaseComponentLoad error handling
Demonstrates how load-phase exceptions are handled in a DwsPageBaseComponent page.
Show Code
LoadingErrorExsamplePage.razor
@* LoadingErrorExsamplePage.razor *@
@inject IDwsToastNotificationService ToastNotification
<DwsPageBaseComponent PageTitle="Load Error Example" PageName="ExampleLoadingPage"
OnPreLoadDataAsync="PreLoad" OnLoadDataAsync="LoadData" OnPostLoadDataAsync="PostLoadData"
OnError="OnPageError">
<Content>
@if (_pageState == null || !_pageState.Success)
{
<DwsAlert Name="Example_LoadError" Severity="DwsSeverity.Error" Message="Error loading data." />
}
else
{
<DwsDataGrid T="WeatherForecast" Items="@_pageState.Forecasts" Name="BaseGrid" Title="Weather Data" InitialPageSize="25" ExportPDF="true">
<DwsDataGridColumns>
<DwsDataGridColumn T="WeatherForecast" Name="Column_City" Field="City" Title="City" Sortable="true" />
<DwsDataGridColumn T="WeatherForecast" Name="Column_TemperatureC" Field="TemperatureC" Title="Temp. (C)" Sortable="true" Alignment="DwsHorizontalAlignment.Right" />
<DwsDataGridColumn T="WeatherForecast" Name="Column_TemperatureF" Field="TemperatureF" Title="Temp. (F)" Sortable="true" Alignment="DwsHorizontalAlignment.Right" />
<DwsDataGridColumn T="WeatherForecast" Name="Column_Wind" Field="Wind" Title="Wind" Sortable="true" />
<DwsDataGridColumn T="WeatherForecast" Name="Column_Summary" Field="Summary" Title="Summary" Sortable="true" />
</DwsDataGridColumns>
</DwsDataGrid>
}
</Content>
</DwsPageBaseComponent>@code
private WeatherPageState? _pageState;
private bool _exceptionThrown;
// Every exception of the load phases ends up here; the page shows its error state on top.
private Task OnPageError(Exception exception)
{
ToastNotification.ShowToast(exception.Message, DwsToastLevel.Error, "Error Event Triggered", 20000);
return Task.CompletedTask;
}
private async Task PreLoad((DwsPageBaseComponent dwsPageReference, CancellationToken cancellationToken) args)
{
await Task.Delay(Random.Shared.Next(200, 1500), args.cancellationToken);
ThrowRandomException();
_pageState = new WeatherPageState { Success = true, Forecasts = GenerateDummyData() };
}
private async Task LoadData((bool firstRun, DwsPageBaseComponent dwsPageReference, CancellationToken cancellationToken) args)
{
await Task.Delay(Random.Shared.Next(200, 1500), args.cancellationToken);
ThrowRandomException();
_exceptionThrown = false;
_pageState = new WeatherPageState { Success = true, Forecasts = GenerateDummyData() };
}
private async Task PostLoadData((bool firstRun, DwsPageBaseComponent dwsPageReference, CancellationToken cancellationToken) args)
{
if (!_exceptionThrown)
{
throw new InvalidOperationException("Guaranteed exception in PostLoadData.");
}
await Task.Delay(1000, args.cancellationToken);
}
private void ThrowRandomException()
{
if (Random.Shared.Next(0, 3) == 0) // 1 in 3 chance
{
_exceptionThrown = true;
throw new InvalidOperationException("Randomly thrown exception for testing purposes.");
}
}
private static WeatherForecast[] GenerateDummyData() =>
[
new() { City = "Test City", TemperatureC = 25, Wind = "5 km/h", Summary = "Sunny" }
];
private sealed class WeatherPageState
{
public bool Success { get; set; }
public WeatherForecast[]? Forecasts { get; set; }
}
private sealed class WeatherForecast
{
public string City { get; set; } = string.Empty;
public int TemperatureC { get; set; }
public string Wind { get; set; } = string.Empty;
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)Math.Round(TemperatureC * 9 / 5.0);
}Interface-Description
| Name | Typ | Parameters | Description |
|---|---|---|---|
| OnUpdate | Task | Triggers a manual reload cycle and executes load callbacks again. |
| Name | Typ | Default | Description |
|---|---|---|---|
| OnLoadDataAsync | EventCallback<(bool firstRun, DwsPageBaseComponent dwsPageReference, CancellationToken cancellationToken)> | default | Main async loading callback. Exceptions are routed to OnError. |
| OnError | EventCallback<Exception> | default | Centralized page-level error callback for load/render/runtime failures. |
| ExposeErrorDetails | bool? | null | Shows the exception message and stack trace below the error alert. Unset: only in the Development environment (IDwsEnvironmentInfo), never when the host does not tell its environment. Set it to true or false to decide yourself. |
| EnableAutoUpdateShortCircuit | bool | true | Stops automatic updates after repeated failures. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Element | ElementReference | The associated web component. May be null if accessed before the component is rendered. | |
| ComponentGuid | Guid | Unique identifier for the component. | |
| TypeString | string | The name of the component type, obtained from reflection. | |
| Authorized_RegisterEnabled | bool | false | Indicates whether this component is enabled through a permission registry. |
| Authorized_RegisterSelected | bool | false | Indicates whether this component is selected in permission selection mode. |
| GetInitializedState | bool | false | Returns whether the component is initialized. |
| GetRenderModeState | DwsRenderMode | Returns the current render mode. | |
| GetComponentState | DwsComponentStateType | Returns the current component state. | |
| GetIsInteractiveState | bool | false | Returns whether the component is interactive. |
| GetIsPrerenderingState | bool | false | Returns whether the component is prerendering. |
| GetComponentLoadingState | bool | false | Returns whether the component is loading. |
| IsFormBusy | bool | false | Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState). |
| Name | Typ | Parameters | Description |
|---|---|---|---|
| DebugInfo | void | Logs debug information about the component. | |
| UpdateState | void | Updates the component's state and triggers StateHasChanged. | |
| UpdateStateAsync | Task | Asynchronously updates the component's state and triggers StateHasChanged. | |
| Dispose | void | Disposes the component and releases resources. | |
| FocusAsync | ValueTask | bool containedInScrollableList | Sets focus to the component's element. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Name | string | Required unique identifier for the component within its container. | |
| Visible | bool | true | Determines if the component is visible in the UI. |
| Disabled | bool | false | Disables the form control, ensuring it doesn't participate in form submission. |
| ComponentNameSpace | string | The namespace for permission-based access control. | |
| PermissionKey | string? | null | A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins. |
| Class | string | Optional CSS class names. | |
| Style | string | Optional in-line styles. | |
| Tag | object | An optional user-defined object to store any additional data with the component. | |
| BackReference | DwsReference | A reference to the enclosing component. | |
| ID | string | The HTML ID attribute for the component. | |
| AdditionalAttributes | Dictionary<string, object> | Additional HTML attributes for the component's root element. | |
| IgnorePermissionChecks | bool | false | Bypasses all permission checks for this component. |
| IgnorePermissionSelection | bool | false | Ignore permission selection mode for this component. |
| IgnoreFormBusy | bool | false | Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it. |
| Name | Typ | Description |
|---|---|---|
| OnInitializedCallbackStarted | EventCallback | Callback when OnInitialized starts. |
| OnInitializedCallback | EventCallback | Callback during OnInitialized. |
| OnInitializedCallbackCompleted | EventCallback | Callback when OnInitialized completes. |
| OnInitializedAsyncCallbackStarted | EventCallback | Callback when OnInitializedAsync starts. |
| OnInitializedAsyncCallback | EventCallback | Callback during OnInitializedAsync. |
| OnInitializedAsyncCallbackCompleted | EventCallback | Callback when OnInitializedAsync completes. |
| OnIsComponentLoadingChanged | EventCallback<bool> | Callback when IsComponentLoading changes. |
| OnCurrentRenderModeChanged | EventCallback<DwsRenderMode> | Callback when CurrentRenderMode changes. |
| OnComponentStateChanged | EventCallback<DwsComponentStateType> | Callback when ComponentState changes. |
