473,406 Members | 2,633 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,406 software developers and data experts.

AddHandler SelectedIndexChanged Problem

2
Hi,
I just have a problem that I can not workout a solution to.

I have a gridview which gets a bunch of controls created dynamically. What I want to be able to do is have one dropdownlist selection determine what is in the other dropdownlist control. I have the first one being populated fine but just have a problem getting the first selected index value to the second dropdownlist.

For the dropdownlist I have the following:

Expand|Select|Wrap|Line Numbers
  1. AddHandler field_ddl.SelectedIndexChanged, AddressOf OnSelectedIndexChanged
Which calls

Expand|Select|Wrap|Line Numbers
  1.     Private Sub OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
  2.  
  3.         Dim myDropDownListName As String
  4.         Dim myNewValue As String
  5.  
  6.         myNewValue = DirectCast(sender, DropDownList).SelectedValue
  7.         myDropDownListName = DirectCast(sender, DropDownList).ID
  8.  
  9.         myDropDownListName = StringFunctions.JustColumnName(myDropDownListName)
  10.  
  11.         'ParameterArray.Add(myDropDownListName)
  12.  
  13.  
  14.         Dim myHTTP As String
  15.         HttpContext.Current.Session(myDropDownListName) = myNewValue
  16.  
  17.         myHTTP = HttpContext.Current.Session(myDropDownListName)
  18.  
  19.  
  20.     End Sub
What happens is that yes the session variable does get populated at some stage but seems to be happening too late. I want to use the value to build the SQL that will fill the second dropdownlist but the value is not got until after the postback and controls have been populated.

Is there a way to make sure that the OnSelectedIndexChanged sub be called before the postback?

Thanks
Jul 9 '07 #1
4 4613
kenobewan
4,871 Expert 4TB
Welcome to TSDN. Have you tried not ispostback?
Jul 9 '07 #2
qasd3
2
Sorry I dont think that I understand what you are sujesting. The code that I have supplyed is in a seprate class that is being called from the page. What is happening is that the dropdownlist does do the postback there are things that run in the page_load that recreate the items in the gridview. The dropdownlist maintains the selected value from the user. The sub for the dropdownlist item being changed does get fired but this happens after the page_load has recreated the dropdownlists so the value that the user selected can not be used before the dropdownlist items are populated. So what I need is the value from the dropdownlist that has changed to be avaliable before the dropdownlists are being recreated. So something like before the postback or just after the postback in the page_load section is where I think that I need to get the value.

Hope that this gives a bit more information about the problem. Thanks for your reply.
Jul 9 '07 #3
kenobewan
4,871 Expert 4TB
My bad - I misread your question. My belief is that you don't need things to happen before page load or postback. It is the order of things that is important. If you cant create the session earlier in the event you could try using threads to ensure it is created. Here is an article that may help:
Threading in ASP.NET
Jul 10 '07 #4
You could try the following

Session("sessionName") = DataBaseTable.Attribute
DropDownList.DataBind()

for example.

The dataBind will make the session variable apply to the drop down list when you call it.
May 3 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sandman | last post by:
I've got a combo box that has an event handler set for SelectedIndexChanged event. The problem is that it's firing at startup when I load data from the Form_OnLoad event. I tried setting a flag...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
0
by: Jeffrey A. Voigt | last post by:
Can someone take a quick glace at my code and tell me why my AutoPostBackHandler function does not get fired off at all? What I'm trying to do is get all of the Buttons and DropDownList controls...
2
by: Kay | last post by:
Hello, I have a dropdown list control on my form, sometimes I want the SelectedIndexChanged event to be handled and other times I want it to be ignored, so I programmatically add a handler for...
3
by: Clouds | last post by:
Hi ! How do I add the dynamic event handler for a dropdownlist present in the itemtemplate of a datalist !! I am doing it in the itemdatabound event of the datalist but it doesnt work... I am...
1
by: Luis Esteban Valencia Muñoz | last post by:
Have a dropdownlist created in my LoadMain() which is called from the Page_load: ************************PAGE LOAD********************8Private Sub Page_Load(ByVal sender As System.Object, ByVal e...
2
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some...
5
by: Slim | last post by:
i have a simple page, with one button button1. when click it creates a new button button 2 and adds a event handler to it. but when button 2 is clicked nothing happens, why? Partial Class...
2
by: laxmibokka | last post by:
here im trying to create imagebuttons dynamically, and on click of button, the delete function should be called. actually commandargument is not passed into the imgBtn_Click im not getting any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.