DxResourceManager.RegisterScripts(Action<ResourcesConfigurator>) Method
Registers DevExpress client resources and custom scripts.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.Resources.v26.1.dll
Declaration
public static RenderFragment RegisterScripts(
Action<ResourcesConfigurator> action = null
)
Optional Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| action | Action<ResourcesConfigurator> | null | A delegate method that configures the resource collection. |
Returns
| Type | Description |
|---|---|
| RenderFragment | A UI fragment to be rendered on the page. |
Remarks
If you use a DevExpress Blazor project template, your application automatically registers all scripts DevExpress libraries require. To register these scripts in other Blazor applications, call the DxResourceManager.RegisterScripts method in the Components/App.razor file:
<head>
@*...*@
@DxResourceManager.RegisterScripts()
</head>
The method parameter allows you to specify client resources to be registered. The Resources field returns the resource collection. Register(DxResource) and Unregister(DxResource) methods allow you to add or remove scripts. The default script folder is wwwroot.
Note: Omit the method call if you created a hybrid project. Our Blazor components obtain scripts for interaction automatically.
The following example registers a custom script.js script and removes the Quill resource. Quill is unnecessary if an application does not include the HTML Editor component:
@DxResourceManager.RegisterScripts((config) => {
config.Unregister(BlazorResources.QuillJS);
var maxScriptPosition = config.Resources.OrderBy(o => o.Position).Last().Position;
config.Register(new DxResource("script.js", maxScriptPosition + 1));
})
If you register a custom script, call the LoadDxResources(IJSRuntime) method before you execute the script’s API members for the first time. This method forces the Resource Manager to load client resources:
// ...
@code {
[Inject] IJSRuntime js;
protected override async Task OnAfterRenderAsync(bool firstRender) {
if(firstRender) {
await js.LoadDxResources();
await js.InvokeAsync("a-method-from-a-custom-script");
}
await base.OnAfterRenderAsync(firstRender);
}
}
Refer to the following topic for the list of DevExpress resources: DxResourceManager.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RegisterScripts(Action<ResourcesConfigurator>) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.