Hi,
I am trying to use Yes No Confirmation Message Box if i would like to use is a DropDownList.
I need Yes No Confirmation Message Box in DropDownList only if the value selected is equal to 3.
How can i modify the code?
My complete code below
<asp:DropDownList ID="ddl" Width="300px" runat="server" onchange="Confirm()" AppendDataBoundItems="true"
OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="test1" Value="test1"></asp:ListItem>
<asp:ListItem Text="test2" Value="test2"></asp:ListItem>
<asp:ListItem Text="test3" Value="test3"></asp:ListItem>
</asp:DropDownList>
<script type="text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
public void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
}
}