Text value not changing when new value on DropDownList selected

Hi,

I am looking for assistance on how to correctly post events when a new item is selected on a drop down list.

My drop down list has autopostback enabled and a sub routine associated with SelectedIndexChanged. This routine is activated when another entry in the drop down list is selected, however, the value is not changed and the drop down list returns to the originally selected value.

For example, if I have 2 values in my drop down list, 0 and 1, and 0 is the currently selected value. Selecting 1 will trigger the event but the drop down list will return to displaying 0 as the selected value. Even looking at DropDownList.Text in debugger the value is not changing from 0 to 1.

By turning off AutoPostBack the event is not triggered.

Can anybody give advice on what I need to do to correctly trigger an event when the value of a drop down list is changed?

 Thanks.

0
clum
2/8/2008 4:40:15 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

7 Replies
6088 Views

Similar Articles

[PageSpeed] 53

Sounds like your initial Data binding method(s) are getting called again. Are you using the IsPostBack check before calling those methods?

If IsPostBack = false then

    BindData

End If


Chris Love
ASP.NET 2.0 Your Visual Blueprint for developing Web Applications
1
docluv
2/8/2008 4:44:06 PM

 where do you populate your DDL?


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
2/8/2008 4:52:47 PM

I wasn't using IsPostBack, should I be?

Drop Down List has fixed values set using the Edit Items option, but the selected value, when the applicationis running, is determined by a stored proc call. One of the available values in the drop down will be returned from the DB table.

 When the value is changed I'm hoping to use the event to alter the value of another textbox (or field).

 If I'm being too vague here let me know. I can post more details it necessary.

 Thanks for the help.

0
clum
2/8/2008 5:08:57 PM

can you show us the code? 


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
Regards,
Pedro Abraham de la Cruz
0
pcruz
2/8/2008 5:19:30 PM

There's not much to it really.

Early I set the value selected in the DDL by using

myDropDownList.Text = ValueReturnedFromStoredProc

This is the event handler

Protected Sub myDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myDropDownList.SelectedIndexChanged

functionThatDoesMoreStuff()

End Sub

The function I call attempts to use the value in myDropDownList.Text but there is no change to the value of myDropDownList.Text so nothing really happens. And the DDL reverts to the value it was set to before a new value was selected.

The DDL has AutoPostBack set to True, and SelectedIndexChanged Action calls myDropDownList_SelectedIndexChanged. This call works, it's the value not changing that has me stumped. If I turn off AutoPostBack the value changes but the event handler is not activated.

0
clum
2/8/2008 5:31:09 PM

clum:

There's not much to it really.

Early I set the value selected in the DDL by using

myDropDownList.Text = ValueReturnedFromStoredProc

This is the event handler

Protected Sub myDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myDropDownList.SelectedIndexChanged

functionThatDoesMoreStuff()

End Sub

The function I call attempts to use the value in myDropDownList.Text but there is no change to the value of myDropDownList.Text so nothing really happens. And the DDL reverts to the value it was set to before a new value was selected.

The DDL has AutoPostBack set to True, and SelectedIndexChanged Action calls myDropDownList_SelectedIndexChanged. This call works, it's the value not changing that has me stumped. If I turn off AutoPostBack the value changes but the event handler is not activated.

 

Hi clum,

Could you post the whole code here?

Waiting for your feedback,

Hong Gang 


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
2/12/2008 9:37:42 AM

Hi Hong Gang

I eventually figured this one out, it was Chris Love who pointed me in the right direction.

Fairly new to .Net and I didn't realise the Page_Load sub was being tirggered from the PostBack event. In Page_Load the value selected was overwritten, with the DDL being reset to it's original value.

I'm using IsPostBack to avoid this now.

Thanks everybody for your help. In hindsight I probably would have figured this out a lot earlier if I'd set a breakpoint for Debugger at a much earlier stage....

0
clum
2/12/2008 9:49:33 AM
Reply:

Web resources about - Text value not changing when new value on DropDownList selected - asp.net.web-forms

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 1/11/2016 1:01:12 AM