Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to enable/disable the textboxes with autopostback.

Posted on 2012-04-04
5
Medium Priority
?
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

664 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