RadComboBox stops working after adding SelectedItemChanged code

5 posts, 0 answers
  1. dean.carrefour
    dean.carrefour avatar
    43 posts
    Member since:
    Oct 2006

    Posted 04 Aug 2011 Link to this post

    I have a very plain drop down with only a few entries.  Before this morning, the list is populated and you could click on any entry and nothing happened...which was fine because there was no code.  Now I want it to do something when one of the list items is selcted (redirect to another page).  So I added OnSelectedItemChanged = "RadComboBox1_OnSelectedItemChanged" to the html definition of the combobox, then in the code behind I have a function to match that does a Select Case statement and redirects to the appropriate page based on which item the user selects.

    Now that I've added this code I can't click on the ComboBox anymore.  It doesn't drop-down like it should.

    HTML Page:
    Choose Location: 
    <telerik:RadComboBox ID="RadComboBox1" Runat="server" DropDownWidth="200px"
        EnableTextSelection="False" Height="50px" MaxHeight="200px" NoWrap="True"
        Width="200px" OnClientSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="Atlanta" Value="ATL" />
            <telerik:RadComboBoxItem runat="server" Text="Cincinnati" Value="CIN" />
            <telerik:RadComboBoxItem runat="server" Text="Cleveland" Value="CLV" />
            <telerik:RadComboBoxItem runat="server" Text="Dayton" Value="DAY" />
            <telerik:RadComboBoxItem runat="server" Text="Kansas City" Value="KC" />
            <telerik:RadComboBoxItem runat="server" Text="Kansas" Value="KAN" />
            <telerik:RadComboBoxItem runat="server" Text="Memphis" Value="MEM" />
            <telerik:RadComboBoxItem runat="server" Text="Northeast Ohio" Value="NEO" />
            <telerik:RadComboBoxItem runat="server" Text="Oklahoma City" Value="OKC" />
            <telerik:RadComboBoxItem runat="server" Text="Philadelphia" Value="PHL" />
            <telerik:RadComboBoxItem runat="server" Text="St. Louis" Value="STL" />
        </Items>
    </telerik:RadComboBox>



    Code Behind .aspx page:
        Protected Sub RadComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged
            Select Case e.Value
                Case "ATL"
     
                Case "CIN"
     
                Case "CLV"
                    Response.Redirect("http://www.someurl.com/CLV.asp")
     
                Case "DAY"
     
                Case "KAN"
     
                Case "KC"
     
                Case "MEM"
     
                Case "NEO"
     
                Case "OKC"
     
                Case "PHL"
     
                Case "STL"
     
            End Select
        End Sub
    End Class
  2. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 04 Aug 2011 Link to this post

    Hi Dean,

    You are setting the OnClientSelectedIndexedChange property, but have your code server side in the code behind.  The OnClientSelectedIndexedChange property is for attaching a JavaScript function -- for example if you wanted to pop up the question "Are you sure you wanted to do that?"...

    Change the RadComboBox definition to the following and you should be good.
    OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"

    Hope that helps!
    Thad
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. dean.carrefour
    dean.carrefour avatar
    43 posts
    Member since:
    Oct 2006

    Posted 04 Aug 2011 Link to this post

    That got the combobox to work again when I click on it, but if I choose Cleveland, it should take it to my code behind and redirect it, but that even never fires.
  5. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 04 Aug 2011 Link to this post

    Hi Dean,

    Sorry about that - I forgot to mention that you needed to set AllowAutoPostBack="true" as well.  That will actually tell the RadComboBox to post back when the selection changes -- the OnSelectedIndexChanged property tells the server side code which event to invoke when it posts back...

    That should get you going!
    Thad
  6. dean.carrefour
    dean.carrefour avatar
    43 posts
    Member since:
    Oct 2006

    Posted 04 Aug 2011 Link to this post

    That worked.  Duh!  Thanks.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017