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

2 posts, 0 answers
  1. Tim
    Tim avatar
    57 posts
    Member since:
    Apr 2011

    Posted 09 Dec 2011 Link to this post


    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?

  2. Bozhidar
    Bozhidar avatar
    1096 posts

    Posted 09 Dec 2011 Link to this post

    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.

    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
  3. DevCraft R3 2016 release webinar banner
Back to Top