Solved

How to enable/disable the textboxes with autopostback.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

762 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