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
Explain server-side scripting and client-side scripting.
What are the differences between application object and session object?
Difference between .NET and previous version?
What are the different authentication modes in asp.net?
How to prevent client side validation from the ASP.NET validation controls?
What are asp.net web forms?
What is the flow of processing of the request? : asp.net mvc
What is the difference between custom controls and user controls?
What is a reflection?
What is repository pattern in mvc.net? : asp.net mvc
How to unit test Web API?
What is _viewstart?
What are merge modules?
Differentiate between namespace and assembly.
If 200 is for all successful operation then why do we have 201 response codes?