Click here to Skip to main content
15,896,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Dropdown-A and Dropdown-B. Dropdown-A is mandatory.

If a user comes to Dropdown-A and without entering anything if he moves to next available control ( Dropdown-B) either by tabbing or by moving the cursor,

error message should be displayed.



This is My dropdown.dataBind this dropdown

XML
<asp:DropDownList ID="DropDownCountry" runat="server" AutoPostBack="true"
                       CssClass="input" Height="20px"
                       onselectedindexchanged="DropDownCountry_SelectedIndexChanged" TabIndex="18"
                       Width="99%" >
                   </asp:DropDownList>


Could anyone of you please help me by telling in which event to write the validation.i try 2,3 days i cant fix this problum..
Posted
Updated 27-Feb-13 18:06pm
v3
Comments
[no name] 26-Feb-13 4:06am    
anyone of you please help me

Please go thorugh below url for handling lostfoucs event in asp.net and
if LotsFoucs event check droplist.Itmes
JavaScript

function LoseFocus(ddlElem) {

ddlElem.blur();
var val=ddlElem.options[e.selectedIndex].value;
if(val == "" || val == "select")
alert('Error');

}

ASPX

<asp:dropdownlist id="ddlLoseFocus" runat="server" autopostback="true" xmlns:asp="#unknown">

C#

protected void Page_Load(object sender, EventArgs e)

{

ddlLoseFocus.Attributes.Add("onchange", "LoseFocus(this)");

}
 
Share this answer
 
Comments
[no name] 28-Feb-13 0:25am    
<asp:DropDownList ID="DropDownPackType" runat="server" Width="100%" Height="20px"
CssClass="input" AutoPostBack="true"
onselectedindexchanged="DropDownPackType_SelectedIndexChanged"
TabIndex="23" onblur="LoseFocus(this);">
You can achieve by following 2 quick notes:

1. onblur event for Dropdown-A, in this funcion "Check whether the Dropdown-A is selected or not. if not, then Display error messge".

2. onchange event for DropDown- b,in this funcion "Check whether the Dropdown-A is selected or not. if not, then Display error messge".
 
Share this answer
 
Hi,

Try using a required field validator.

hope this link helps you.

http://forums.asp.net/t/1296491.aspx/1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900