Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,

am working on asp.net c#

on my webpage i have two textboxes as TxtCountry and TxtCity

when i enter the text in Txtcountry.... TxtCity must enable. otherwise Txtciuty must disable.

Please help thanks.
Posted
Comments
Marvin Ma 10-Sep-13 3:09am    
Any work done yet ?

In the TextChanged even of the first textbox(i.e txtcountry), just enable the txtcity ..
and in the page load make that txtcity.enable=false..

Hope it will do the trick..
 
Share this answer
 
try this hope it will help you
C#
if(TxtCountry.Text=="")
{
    txtcity.enable=false;
}
else
{
    txtcity.enable=True;
}
 
Share this answer
 
v3
Hi,
you can do it by enabling keyup event of Txtcountry.
JavaScript
$("#<%= TxtCountry %>").keyup(function (event) {
      if($("#<%= TxtCountry %>").val() == '')
      {
          $("#<%= TxtCity %>").attr("disabled", "disabled"); 
      }
      else
      {
          $("#<%= TxtCity %>").removeAttr("disabled");
      }
   });

Hope it helps.
 
Share this answer
 
v2
I have a Solution...
Add two text box like this..

C#
<asp:textbox id="TxtCountry" onkeypress="change()" runat="server"></asp:textbox>
       <br />
<asp:textbox id="Txtcity" runat="server" enabled="False"></asp:textbox>



Then set enabled=false property of TxtCountry.
After that just write the javascript to that page like below..

JavaScript
<pre lang="Javascript"><script type="text/javascript">
        function change() {
            document.getElementById("Txtcity").disabled = false;
        }
    </script>



Don't forget to add script manager to the page...
I hope you satisfied with this solution...
Have a good day..
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900