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's the difference between viewstate and sessionstate?
What is the difference between the asp and asp.net?
How can we identify that the page is post back in asp net?
How you can add an event handler?
what are the events raised in asp.net page life cycle?in which stage view state can be loaded?
Define xmlvalidatingreader class.
What a diffgram is, and a good use for one?
What is a nested masterpage in asp.net 2.0? Can there be a master page inside a masterpage?
Why is global asax is used for?
Define authentication and authorization.
What is the purpose of master page?
What does the hotspot class in .net do?
Differentiate globalization and localization.
Describe the sequence of action takes place on the server when ASP.NET application starts first time?
Which authentication uses a combination of windows and iis authentication?