---
title: "Show Confirmation Message Yes or No in Asp.Net"  
description: "Show Confirmation Message Yes or No in Asp.Net"  
author: "Anonymous User"  
published: 2014-12-21  
updated: 2014-12-22  
canonical: https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net  
category: "asp.net"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Show Confirmation Message Yes or No in Asp.Net

I have [drop](https://www.mindstick.com/forum/159392/how-to-fetch-the-value-of-the-selected-options-in-drop-down-in-php)-down box where [users](https://www.mindstick.com/news/2244/issue-preventing-users-from-accessing-facebook-s-social-networking-platforms-has-been-resolved) can [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) [Yes](https://www.mindstick.com/forum/157763/how-to-return-yes-no-based-on-date-comparison-in-sql) or No, if user selects Yes from the drop-down then i want to show a confirmation box that [shows](https://yourviews.mindstick.com/view/81380/new-york-violent-shooting-shows-people-are-not-safe-in-night-life) Yes or No option. If only user selects Yes in the confirmation box then i want to proceed calling my other [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) which makes an [update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) to the [backend](https://www.mindstick.com/articles/337404/how-to-build-and-consume-restful-apis-using-php) database. If user selects No in the confirmation box then i don't want to proceed and [cancel](https://answers.mindstick.com/qa/94501/how-can-i-cancel-my-singapore-flight-ticket) the operation. Here is my drop-down [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
OnSelectedIndexChanged="CheckDropDownSelection"                        runat="server" AppendDataBoundItems="true" Height="16px">                        <asp:ListItem Text="-- Please Selet --" Value="-- Please Selet --"></asp:ListItem>                        <asp:ListItem Text="YES" Value="YES"></asp:ListItem>                        <asp:ListItem Text="NO" Value="NO"></asp:ListItem>                    </asp:DropDownList>here is my code behind: protected void CheckDropDownSelection(Object sender, EventArgs e)    {        if (ddl_CloseTask.SelectedValue == "YES")        {            CloseTask();        }        else        {         }    }     protected void CloseTask()    {         // here is where i close the task    }
```

## Replies

### Reply by Anonymous User

This is how you can achieve with sever and client side code

attach event of client code mostly in page_load

yourDropDownList.Attributes["onChange"] = "jsFunction(this);";

## Client script

```
function jsFunction(mlist){  var myselect = mlist;  if(myselect.options[myselect.selectedIndex].value == "YES")  {    if(confirm("Delete item!"))    {      $.ajax({       type:"POST",         url: window.location.pathname + "/CloseTask";,           data: dataString,          contentType:"application/json; charset=utf-8",            dataType:"json",         error:                  function(XMLHttpRequest, textStatus, errorThrown) {                         $(errorlableid).show();                         $(errorlableid).html("Error");                  },         success:             function(result) {                 }         }         }      });    }  }}
```

## serverside code

```
[WebMethod]protected void CloseTask(){    //code to close task }
```

### Reply by Anonymous User

The code has too many Yes/No. I hope it won't confuse to user -

If a user selects YES in DropDownList, a Confirmation Message will be prompted.

If the user selects YES in Confirmation Message, DropDownList will post back to server.

```
<asp:DropDownList ID="ddl_CloseTask" Width="157px"    AutoPostBack="true"    OnSelectedIndexChanged="CheckDropDownSelection"   runat="server"    AppendDataBoundItems="true" Height="16px">   <asp:ListItem Text="-- Please Selet --" Value="-- Please Selet --"></asp:ListItem>   <asp:ListItem Text="YES" Value="YES"></asp:ListItem>   <asp:ListItem Text="NO" Value="NO"></asp:ListItem></asp:DropDownList> <script type="text/javascript">    var selectlistId = '<%= ddl_CloseTask.ClientID %>',        selectlist = document.getElementById(selectlistId);     selectlist.onchange = function() {        if (selectlist.options[selectlist.selectedIndex].value == "YES") {            if (confirm("Are you sure you want to do this?")) {                __doPostBack(selectlistId, '');            }        }    };</script>
```


---

Original Source: https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
