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

x
?
Solved

dropdownlist.text returning incorrect value after autopostback on another dropdownlist

Posted on 2011-02-25
8
Medium Priority
?
738 Views
Last Modified: 2012-05-11
Hi,

Can't quite see what's going wrong here, and it's a little complicated so i'll try and explain as best i can. I have a number of dropdownlists (we'll call this set 1) which are all databound and filled using sqldatasources. If I select one of them, it fills another dropdownlist using some javascript (we'll call this set 2), then the user selects one of those options clicks a button and the data required is returned. That all works fine.

So, I can switch between the different dropdownlists fine and the correct value is always returned (from set 1). However, 1 of the dropdownlists in set 1 is an autopostback dropdownlist. And this is where the problem occurs. If I hit the autopostback dropdownlist that works fine. But, if I then go to hit another dropdownlist of set 1, which fills set 2 and user clicks a button... I find that the dropdownlist.text value which is returned is incorrect (it is always the first element of the dropdownlist). If I hit the dropdownlist again, then the correct value is returned.

This is the order of the problem:
(1) Select value in databound autopostback dropdownlist. Data returns fine.
(2) Select value in one of the other databound dropdownlists (not autopostback). First value in dropdownlist is seen in codebehind even though i selected some other value
(3) Perform step two for a second time. Correct value now shown in codebehind.

What's going on here can anyone see?
0
Comment
Question by:AidenA
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34978812
Sounds like you are repopulting the contents of the dropdownlist on pageload, maybe not checking for Page.IsPostBack. POst your code so we can determine what's going on.
0
 
LVL 10

Expert Comment

by:John Claes
ID: 34978861
it looks like your changing the text, but the element is not changed (not found)
Therefor the element can't be set and using the postback the first element is returned as selected Item.

0
 

Author Comment

by:AidenA
ID: 34979117
the dropdownlists are databound with sqldatasources... so the text can't change in any of them (only in the set 2 dropdownlists... but i'm not looking for those values... i'm looking at set 1 dropdown values which are all databound)...

that's what's weird about this... the data must be populating with the same values each time the page loads... so there should be no possiblity of the data not being there. + it only doesn't work immediately after the dropdownlist with autopostback is selected. After that (i.e. the second time I click the button looking for the selected value of the non autopostback dropdown) there is no problem... the value which was selected is found?
0
Stressed Out?

Watch some penguins on the livecam!

 

Author Comment

by:AidenA
ID: 34979124
and just to be clear, the sqldatasources are on the page... i'm not binding dynamically or creating any datasources dynamically...
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34986863
Can you post your code so we can try and help further
0
 

Author Comment

by:AidenA
ID: 35005597
sorry I figured it out. It's an MS Access problem, or a general database problem, I'm not sure. Although I'm sitting here trying to remember exactly what the issue was and since i was fixing so many things over the last few days i just can't exactly remember.

I'm pretty sure though it was to do with the fact that I was running a query on an MS Access database, and then directly afterwards extracting the result and putting it into a label on the page so i could search through it in javascript and fill the dropdowns. Anyway, what i found what that if after running the first query i put a thread.sleep for 10 seconds before extracting the results into the label, it worked ok, but if i didn't do that, then what was extracted was not the updated table.

So, it looks like access needs a few moments to update it's query, but when I'm running the second query to extract the updated results, the table isn't updated yet. How do you get around this problem? I think for those queries i was just using ado recordsets. I assume though the problem would be the same with ADO.NET? What about in Oracle... would you have a similar problem and how to solve?
0
 
LVL 10

Accepted Solution

by:
John Claes earned 2000 total points
ID: 35190963
As far as I know this issue this is not a ADO issue but a Access Issue.

Databases are made to cache a lot of data to make Queries Quicker.
It seems that you were requesting data from the Cache while you already changed the recordset itself.
I had this 3 years ago when I was working on a Access Database. I used that to get the customer to a SQL DB and I never had that issue again.

regards

poor beggar
0
 

Author Comment

by:AidenA
ID: 35192512
ok, i was assuming it was an ms access problem. The website will be migrated to oracle soon... but then i'll have a whole new set of problems i'm sure.

thanks for help..

Aiden
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 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