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
What is ispostback property?
What does clearing cache?
What is simple data binding?
What is the main difference between Asp.net and Vb.net?
How is application management and maintenance improved in asp.net 2.0?
What are the 3 types of web?
Can you explain the importance of finalize method in .net?
Which is better union or union all?
Which method has beenintroduced in asp.net 4.0 to redirect a page permanently?
What is the significance of attaching a profile while creating a user?
Explain the working of passport authentication.
What is viewstate in asp net with example?
How asynchronous call can be implemented using delegates?
Explain the concept of MVC Scaffolding?
What is the difference between a cookie and a pixel?