Click here to Skip to main content
11,705,208 members (52,470 online)
Rate this: bad
Please Sign up or sign in to vote.

I have the code to auto select the first item in a listbox, and when i start the web page , the first item is selected, but the other code that i have after the selection has been made its not firing.
When i select the second item and then the first one again, everything works fine.

Best Regards
Posted 30-May-12 1:49am
Rajesh Kariyavula at 30-May-12 8:19am
May I know where you are setting the SelectedValue for the ListBox in the Page Load event.
Member 8956437 at 30-May-12 9:35am
im using the actual value from the listbox in some sql commands
Ed Nutting at 30-May-12 14:20pm
Sorry do you mean that when you auto-select the first item in your list you expect your (I assume you have from what you imply), your selection change event to be called? If so you are mistaken as to what you are doing. Selecting an item in server rendering code (in the Page_Load event) does not cause (and physically cannot cause) a post back and so not event gets fired - just think about the request lifecycle! Where as the user (you) selecting the first item (regardless of what was selected before) does cause a post back from client (you) to the server where your event is then fired. If you want to run code after auto-selecting the first item, you will have to call your method after selecting the item in the Page_Load event.

deepureddy18 at 1-Jun-12 8:29am
mention autopostback= true ...
Kaushik Saha from Kolkata,India at 10-Jul-12 10:30am
If u clarify your problem with some code snippets

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 525
1 OriginalGriff 244
2 ppolymorphe 126
3 F-ES Sitecore 110
4 Andy Lanng 85
0 OriginalGriff 8,988
1 Sergey Alexandrovich Kryukov 8,272
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100