Live Chat Icon For mobile
Live Chat Icon

How to pop up a message box when no item in the dropdownlist is selected before postback?

Platform: ASP.NET| Category: Client Side Scripting
  • Make sure to add a ListItem with Text=’Please Choose’ and Value =”.
  • Add a RequiredFieldValidator with ControlToValidate= <Dropdownlist1> and Display=’Dynamic’
  • Add a ValidationSummary with ShowMessageBox =true

<asp:DropDownList id='DropDownList1' runat='server'>
	<asp:ListItem Value=''>Please Choose</asp:ListItem>
	<asp:ListItem Value='Faq'>Faq</asp:ListItem>
	<asp:ListItem Value='Tips'>Tips</asp:ListItem>
	<asp:ListItem Value='Tricks'>Tricks</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator id='RequiredFieldValidator1' style='Z-INDEX: 102; LEFT: 176px; POSITION: absolute; TOP: 48px'
	runat='server' ErrorMessage='Please Select an Item in the dropdownlist' ControlToValidate='DropDownList1'
	Display='Dynamic'></asp:RequiredFieldValidator>
<asp:Button id='Button1' style='Z-INDEX: 104; LEFT: 128px; POSITION: absolute; TOP: 16px' runat='server'
	Text='Button'></asp:Button>
<asp:ValidationSummary id='ValidationSummary1' style='Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 72px'
	runat='server' ShowMessageBox='True' ShowSummary='False'></asp:ValidationSummary>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.