by bryian
15. February 2010 13:30
User want to see a popup confirmation dialog box on LinkButton click, only if the DropDownList.SelectedValue == ?
See example below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="ddlTest">
<asp:ListItem Selected="True">select</asp:ListItem>
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
<asp:ListItem>d</asp:ListItem>
<asp:ListItem>e</asp:ListItem>
</asp:DropDownList>
<asp:LinkButton ID="IsertButton"
runat="server"
Text="Insert" onclick="IsertButton_Click"
OnClientClick="return CheckIfZeroSelected();" />
</div>
</form>
<script type="text/javascript">
function Insert_Confirmation() {
if (confirm("Are you certain that you want to insert with selected value 0?"))
return true; else return false;
}
function CheckIfZeroSelected() {
var selObj = document.getElementById('<%= ddlTest.ClientID %>');
if (selObj.selectedIndex === 0) {
return Insert_Confirmation();
}
}
</script>
</body>
</html>