Solved

How to enable/disable the textboxes with autopostback.

Posted on 2012-04-04
5
399 Views
Last Modified: 2012-04-05
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
0
Comment
Question by:searchsanjaysharma
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 37809860
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
0
 

Author Comment

by:searchsanjaysharma
ID: 37809970
can  u implement in the given .aspx
0
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 500 total points
ID: 37810161
I think you could do it yourself but anyway here it is

HTH

Ivo Stoykov

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<script type="text/javascript" >
  function test(id) {
    document.getElementById(id).disabled = false;
  }
</script>
<script language="C#" runat="server">
  protected void Page_Load(object sender, EventArgs e)
    {
//I want to enable t2 if t1 is entered.
//Similarly t3 should be enabled if t2 is entered.
      t1.Attributes.Add("onfocus", "test('" + t2.ClientID + "')");
      t2.Attributes.Add("onfocus", "test('" + t3.ClientID + "')");
    }
</script>
<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"/>    
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 37810168
This may be easier on the client instead.

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

Open in new window

0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37810307
ok
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop and hide/show dropdown option with jQuery 4 22
Objects on Same Line 2 18
Code works but it's slow 24 45
how to avoid redundand ajax calls 5 10
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now