I want to use SCEditor in my Blazor page.
For example I create a new Blazor WASM project and I did these steps:
According to documentation I add this codes and references to
index.html:- https://cdn.jsdelivr.net/npm/sceditor@3/minified/themes/default.min.css
- https://cdn.jsdelivr.net/npm/sceditor@3/minified/sceditor.min.js
- https://cdn.jsdelivr.net/npm/sceditor@3/minified/formats/bbcode.min.js
window.InitEditor = () => { var textarea = document.getElementById('myTextArea'); sceditor.create(textarea, { format: 'bbcode', style: 'https://cdn.jsdelivr.net/npm/sceditor@3/minified/themes/content/default.min.css' }); };Add a
textareaincounterpage:<textarea id="myTextArea" style="width:100%; height:200px;"></textarea>add follow code to code section of
counterpage:protected override Task OnAfterRenderAsync(bool firstRender) { JsRuntime.InvokeVoidAsync("InitEditor"); return base.OnAfterRenderAsync(firstRender); }
Now I run the project and I see this editor:
then I click on fetch data menu and I see this:
Surprisingly, editor has shown in fetch data page. if I click on counter page again I see this:
There are 2 Editors O-O. and if I click on this menus then editors are increasing...
I changed the code this way:
protected override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
JsRuntime.InvokeVoidAsync("InitEditor");
return base.OnAfterRenderAsync(firstRender);
}
the editor is shown once in counter page and fetch data page. Again I don't have any textarea in fetch data page.
How can I solve this problem?




