Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I want to show warning message on click of the button.
I should call the warning message from aspx.cs file.
and I need to send one parameter for the message.
like "Do you Want to delete "MYPARAMETER" file"
and in the warning message on click of ok I need to continue with the next step of activity from my aspx.cs page

How to perform this activity..
If I use Javascript How to send parameter from .cs file and how to get the control back to my page.

Or any other way to do it.

Please share with me.


Thanks in advance
Posted

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.

JavaScript
<script src="//code.jquery.com/jquery-1.11.0.min.js">
   // library has been included in the src attribute
   $(document).ready(function () {
       // get the file name
       var filename = $('showerror').data('file-name');
       $('showerror').click(function () {
          // clicked, now check for the confirm box
          if(confirm('You are about to delete the file')) {
             // run the URL here with the file name
          }
       }
   });
</script>


This way you can confirm and then continue. Otherwise cancel the request (that has never been called).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900