Solved

How to enable/disable the textboxes with autopostback.

Posted on 2012-04-04
5
396 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

747 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

10 Experts available now in Live!

Get 1:1 Help Now