473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Autopostback Confusion.

I want to conditionally enable a textbox based on the selection of a
dropdown.

I have 2 entries in the dropdown: Nothing (value 99), Enabled (value
1), Disabled (value 0). Autopostback on the dropdown and textbox are
set to true.

The code in Page_Load is ...

private void Page_Load(object sender, System.EventArgs e){
this.TextBox1.Enabled = this.DropDownList1.SelectedValue == "1";
}

This works fine, for one change in the dropdown selection. After I
change the value a second time it stops working.

My background is windows programming, so I am not entirely comfortable
with this. I searched the group and the help pages to see what the
problem could be, but didn't see anything. Any help is appreciated.

- K.

Apr 20 '06 #1
3 982

I created a web form.

I added a:

DropDownList
TextBox
Label.

Here is my code. It works for me.

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

if (!Page.IsPostBack )

{

LoadDDL();

}

}

private void LoadDDL()

{

ListItem li = new ListItem("--Select--", "0");

this.DropDownList1.Items.Add (li);

li = new ListItem("Enable Me", "1");

this.DropDownList1.Items.Add (li);

li = new ListItem("Disable Me", "2");

this.DropDownList1.Items.Add (li);

}

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)

{

if (this.DropDownList1.SelectedItem.Value == "2")

{

this.TextBox1.Enabled = false;

this.Label1.Text = "false";

}

else

{

this.TextBox1.Enabled = true;

this.Label1.Text = "true";

}

}

Before you do shortening ... like
this.TextBox1.Enabled = this.DropDownList1.SelectedValue == "1";

I'd break it down into parts first, since your new to the controls.


<ke***************@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
I want to conditionally enable a textbox based on the selection of a
dropdown.

I have 2 entries in the dropdown: Nothing (value 99), Enabled (value
1), Disabled (value 0). Autopostback on the dropdown and textbox are
set to true.

The code in Page_Load is ...

private void Page_Load(object sender, System.EventArgs e){
this.TextBox1.Enabled = this.DropDownList1.SelectedValue == "1";
}

This works fine, for one change in the dropdown selection. After I
change the value a second time it stops working.

My background is windows programming, so I am not entirely comfortable
with this. I searched the group and the help pages to see what the
problem could be, but didn't see anything. Any help is appreciated.

- K.

Apr 20 '06 #2
Thank you for the very fast feedback.

Using this code in a new form with autopostback = true for
DropDownList1, I get the same behavior that I had before.

The first time I change the selection in the dropdownlist, the enabled
state is set correctly. Subsequent changes to the dropdown do not
change the enabled state. I see no evidence that the event is firing a
second time.

Apr 20 '06 #3
Solution:

C:\WINNT\Microsoft.NET\Framework\v2.0.40607\aspnet _regiis.exe -u
C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_ regiis.exe -i

Apr 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Susan van Houen | last post by:
Hi All, How do I intercept an autopostback on the client side and prevent it from executing the submit? In classic ASP I used to intercept the on_submit and just return false;
8
by: Matthew Louden | last post by:
why need to set autopostback property to be true?? I know autopostback event means to send the form to the server automatically. I tried checkbox, checkbox list, radio button, and radio button...
4
by: Scott M. | last post by:
If I put RequiredFiledValidators on a page and set them up with corresponding TextBoxes everything works just fine. If I add a DropDownList and set its AutoPostBack to True, I am able to post data...
6
by: Sunil | last post by:
Dear All I am a bit confused about AutoPost Back. My concept about AutoPostBack is that If AutoPostBack i "TRUE" for a Web Form the Web Form Goes back to the server and displays a fresh copy of...
0
by: Scott | last post by:
Hi. I'm having some problems with AutoPostBack in my asp.net pages running on Windows 2003/IIS 6. The pages are really simple. For example, one of them contains two dropDownLists. The firstdrop...
2
by: Tom Edelbrok | last post by:
Question: Why does a button event (ie: Button1_Click) get executed on the first click for a textbox control which has 'autopostback=false', but doesn't get executed until a second click when...
2
by: rn5a | last post by:
Assume that a user control has a TextBox (Page1.ascx) <asp:TextBox ID="txtName" runat="server"/> I am encapsulating the above user control in a ASPX page named Page1.aspx i.e. the ASPX page...
0
by: andy | last post by:
Hi, I have a form uses several dropdownlists to narrow a set of criteria. ( This is in turn used to control what is shown on a gridview. ) With each, the user selects an entry and then the next...
6
by: Peter | last post by:
ASP.NET 2.0 Visual Studio 2008 I have the following code and when the textbox displays and I press Enter while in the text box I get AutoPostBack, how do I stop AutoPostBack? TextBox txt =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.