This is a migrated thread and some comments may be shown as answers.

How to correctly select a listbox item so a selection change occurs

1 Answer 93 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 09 Dec 2011, 03:25 PM
Hi

I have what I thought was a very simple requirement, and maybe it is.

I have a ListBox that contains a few items, that I add programmatically in Server side code.

As each item is selected I want to dynammically load a use control and present it to the right of the ListBox.

Actually I have all of this working just fine.
Again I am using a server side selection changed event to control the dynamic loading. 

However I would like to set the intial selection to the first item in the listbox.
I have tried to do this after the LB is loaded, and I have set the first item to selected just before adding it to the LB.

In neither case do I get a selection change event so I can load the initial dynamic control.

What am I missing?

Do I just have to write extra code to load this control seperate from the SelectionChanged event I am relying on now?

TIA  

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 09 Dec 2011, 06:36 PM
Hi Tim,

If you want to load an initial user control, I would suggest that you do it in the Page_Load server event. If you use the selection changed mechanism for loading the initial user control, you make an unnecessary postback. Try the following:

1. Extract all the code from the RadListBox1_SelectedIndexChanged event handler in a function, and in the handler just call the function. You can pass the index or value to the function, to determine which listbox item was selected

2. In the Page_Load event handler, if the page isn't a postback, call the same method (with argument 0, if you are using index to determine the listbox item)

Hope this is helpful.

Greetings,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ListBox
Asked by
Tim
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or