Link to home
Start Free TrialLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

How to enable/disable the textboxes with autopostback.

I have 5 textboxes.
<asp:TextBox id="t1" runat="server" Text=""/>
<asp:TextBox id="t2" runat="server" Text="" Enabled="false"/>
<asp:TextBox id="t3" runat="server" Text="" Enabled="false"/>
<asp:TextBox id="t4" runat="server" Text="" Enabled="false"/>
<asp:TextBox id="t5" runat="server" Text="" Enabled="false"/>

I want to enable t2 if t1 is entered.
Similarly t3 should be enabled if t2 is entered.
and so on.

with Autopostback=true
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

If you need to change the state when TB is entered, you need client side script. Autopostback does nothing with this.
Add this
protected void Page_Load(object sender, EventArgs e)
    {
      t1.Attributes.Add("onfocus", "test('" + t2.ClientID + "')");
    }

Open in new window

and somewhere in the HTML - this
<script>
      function test(id) {
        document.getElementById(id).disabled = true;
      }
    </script>

Open in new window


Hope you'll get the idea.

HTH

Ivo Stoykov
Avatar of searchsanjaysharma
searchsanjaysharma

ASKER

can  u implement in the given .aspx
ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This may be easier on the client instead.

$("input").change( function() {
    $(this).next("input").attr( {disabled: false} );
});

Open in new window