0

I want to call a code behind method from JavaScript. Here is the scenario: the user will see messagebox in which he/she can select Yes or No. If user selects Yes from the messagebox i want to call the Delete method in code behind else i want to call the Insert method. here is JS:

 <script type="text/javascript" language="javascript">
        function Func() {
            var result = confirm('Are you sure you want to delete?');
            if (result) {
                //click ok button
                //Call the Delete Method
            }
            else {
                //click cancel button
                //Call the Insert method
            }
        }
</script>

here is how my code-behind look like:

protected void Delete()
{
  //delete code here
}
protected void Insert()
{
  //insert code here
}
2
  • 1
    Look up "WebMethod", "Ajax" or "ASP.NET WebAPI" on Google. I'll have a duplicate link shortly. Commented Apr 28, 2014 at 20:17
  • If you're using a databound control (e.g., ListView or GridView) that provides its own Delete button fully wired up, you can hook in a validation javascript. Otherwise, you're tasked with writing up the entire end-to-end client->server conversation yourself. Commented Apr 28, 2014 at 20:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.