Working with Client side and Server side all on the server side is a bit of confusing and hard task to do.
What you can do is something like you seperate each job to their own particular departments. You handle the Client side actions on the Client side (JavaScript) and then handle the Server side on the Server side (C#).
First of all, create a button that would alert the user that he's going to do something that is unchangeable. Since HTML5, you're allowed to have your own custom data attributes in the element. Populate that attribute with the Filename instead of calling a C# code to get the file name.
<button id="showerror" data-file-name="file-name.png">Delete</button>
The jQuery library of JavaScript has got you covered to write less do more. You can include the jQuery code to your document and execute the jQuery code to first of all alert the user and after that, send a request to the server side to delete the file. While sending request you will write the URL of the page where the file will be deleted, this way you only get passed on to the page if the user confirms. For that you can make use of the
confirm
dialog box.
<script src="//code.jquery.com/jquery-1.11.0.min.js">
$(document).ready(function () {
var filename = $('showerror').data('file-name');
$('showerror').click(function () {
if(confirm('You are about to delete the file')) {
}
}
});
</script>
This way you can confirm and then continue. Otherwise cancel the request (that has never been called).