Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


In a page there is dropdown list with the name of the
cities like Bangalore,Pune,Chennai,Other and a text box
that would enable the user to enter the name of the city if
other is selected. How to enable validation on the text box
if other is selected

Answers were Sorted based on User's Feedback



In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / guneetinder singh

By using custom validator.

Is This Answer Correct ?    16 Yes 2 No

In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / swethasri

Client Side validation:
A Javascript function can be written to disable/enable the
text box and it can be called under
DrowpDownList_SelectIndexChanged event. We can provide an
if condition and get the required change in javascript
function.

or else

Server side validation:
we can make the dropdownlist 'AutoPostBack' property true.
and under the DrowpDownList_SelectIndexChanged event, we
can disable/enable the textbox.

Is This Answer Correct ?    11 Yes 3 No

In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / rajesh

by using javascript function can be written to
disable/enable the text box and it can be called under
DrowpDownList_SelectIndexChanged event.

Is This Answer Correct ?    4 Yes 0 No

In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / devkranth kishore

U can do it By Adding a Required validator To the textbox
with enabled is false...

no in the Drop downList selected IndexChanged make it
enable True... this will solve the Isssue

Is This Answer Correct ?    4 Yes 2 No

In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / deepak

just write a javascript function like this
on button click or on onkeypress event of text box

function validate()
{
if(document.getelementbyid("ur dropdownlist").value=="other")
{
if(document.getelementbyid("ur textbox").value=="")
{
alert("please enter city name");
return false;
}

}

}

and call like this onkeypress='return validate()'

Is This Answer Correct ?    4 Yes 2 No

In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / sai krishna

In aspx page

<asp:DropDownList ID="DropDownList1" runat="server"
Width="176px">
<asp:ListItem>Pune</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Hyderabad</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>

<script language="javascript" type="text/javascript">
var other1 = window.document.getElementById("TextBox2");
other1.disabled = true;
function ValidateOtherCity()
{
var other = window.document.getElementById
("DropDownList1");
var other2 = window.document.getElementById
("TextBox2");
if(other.value == 'Other')
{
other2.disabled = false;
}
else
{
other2.disabled = true;
}
}
</script>


In aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Attributes.Add
("OnChange", "javascript:ValidateOtherCity();");
}

Is This Answer Correct ?    2 Yes 0 No

In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / udai

On_page load
{
RequiredFieldValidator1.Enabled = false;
}

if (DropDownList1.SelectedItem.Text == "Other")
{
RequiredFieldValidator1.Enabled = true;
}
else
{
RequiredFieldValidator1.Enabled = false;
}

Is This Answer Correct ?    4 Yes 3 No

In a page there is dropdown list with the name of the cities like Bangalore,Pune,Chennai,Other and..

Answer / swetha v

Hi Friends,

I hope the below solution helps....

1. Please add the required field validator for the texbox.
2. In Page_Load method, we can add the below statement

Dropdownlist.Attributed.Add
("OnChange","javascript:ValidateOtherCity();")

Add the below javascript function on the aspx page

function ValidateOtherCity()
{
var other = window.document.getElementById
("DropdownlistName");

if(other.value == 'Other')
{
ValidatorEnable(RequiredFieldValidatorName,true);
}
else
{
ValidatorEnable(RequiredFieldValidatorName,false);
}
}

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More ASP.NET Interview Questions

Which protocol is used to call a web service?

0 Answers  


What event handlers can I include in Global.asax ?

1 Answers  


what is the cursor

1 Answers   Wipro,


In a webservice, need to display 10 rows from a table. Which is the best choice among datareader or dataset?

0 Answers  


what is the generics and where used generics in your project?

3 Answers   CTC,


what is use to destroy an object? illustrate.

2 Answers   Patni,


how to update data set?

3 Answers   IBM, TCS,


Can more than one person use the same login?

0 Answers   MCN Solutions,


Give real time examples for polymorphism, encapsulation, inheritance..

2 Answers   L&T,


What is difference between user control and custom control?

1 Answers   TVS,


Explain the life cycle of an ASP .NET page

2 Answers   HCL, Surya Software,


will this code works fine? or will it gives error? Object obj=5; int i=6; i=i+obj;

1 Answers   Patni,


Categories