Creating a message box, if Dropdown answer is yes. VB.Net
I have a working dropdown box that gives the answers yes & no. When "yes" is selected I need t开发者_如何学Co create a message box that displays a simple message and allows the user to click ok, to get back to the survey.
I have been working with it, and tried several things but no luck. What would the code look like, and where exactly would I place it to fire at the right time. I am working in VB, with an aspx & aspx.vb page. Thanks in advance.
one sort of classic way to do this is add the onchange
attribute to the DropDownList
Dim message As String = "Custom Message"
DropDownList1.Attributes.Add("onchange", "if (this.value === 'yes') alert('" + message + "');")
Remember that message boxes on the web are a client technology, so you'll have to do this via javascript, using the alert()
function.
The below code should help you get something similar for your page.
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
</style>
<script type="text/javascript">
function ShowAlert()
{
var dropDownList = document.getElementById("DropDownList1");
var dropDownListValue = dropDownList.value;
if (dropDownListValue == "1")
{
alert('This is your message box!');
}
};
</script>
</head>
<body>
<form runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" onchange="ShowAlert();">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:DropDownList>
</form>
</body>
精彩评论