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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is ispostback property?

499


What does clearing cache?

530


What is simple data binding?

511


What is the main difference between Asp.net and Vb.net?

561


How is application management and maintenance improved in asp.net 2.0?

533






What are the 3 types of web?

502


Can you explain the importance of finalize method in .net?

582


Which is better union or union all?

555


Which method has beenintroduced in asp.net 4.0 to redirect a page permanently?

521


What is the significance of attaching a profile while creating a user?

559


Explain the working of passport authentication.

539


What is viewstate in asp net with example?

523


How asynchronous call can be implemented using delegates?

537


Explain the concept of MVC Scaffolding?

582


What is the difference between a cookie and a pixel?

474