Answer:
We suggest using the Microsoft JsInterop to achieve this requirement. We can call a JavaScript method in the Created event of Grid,ListView and bind the JavaScript’s copy event for Grid and ListView. Now in the JS method, We can prevent the copy action to be performed. Please refer to the codes below.
public async Task Created()
{
await IJSRuntime.InvokeAsync<object>("copypasteeventprevent");
}
function copypasteprevent() { document.getElementById("GridData").addEventListener("copy", function (evt) { // Prevent the default
copy action evt.preventDefault(); }, false); } function copypasteeventprevent() { document.getElementById("list").addEventListener("copy", function (evt) { // Prevent the default
copy action evt.preventDefault(); }, false);
} |
Note: The js file is created under wwwroot.
Find the sample to prevent data from being copied in Blazor Grid and ListView from
here.