Can't get Combobox Object

4 posts, 0 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 23 Nov 2009 Link to this post

    I have a combo box within a rad panel bar. I am trying to redirect based on if the user selects something within it. However, right now I'm just getting a JS alert saying object not set to the instance of an object. Here is the relevant code. You can see what I mean at alpha.clickablecommunity.com the page should redirect to calendar.aspx when the user selects that from the dropdown.

        Protected Sub viewDrop_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
            Dim dropdown As RadComboBox = DirectCast(RadPanelBar1.FindItemByText("Places to Go").Items(0).FindControl("veiwDrop"), RadComboBox)
            
            If dropdown.SelectedValue = "calendar" Then
                Response.Redirect("Calendar.aspx")
            End If
                    
        End Sub
    </script>

    And the aspx I didn't paste it all but the panel bar works fine.

    <link href="../ClickableCommunity.css" rel="stylesheet" type="text/css" />
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" Width="220px" Height="520px" BorderStyle="None">
        <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Web20"
            AllowCollapseAllItems="false" Width="220px" BorderStyle="None" OnClientItemClicked="itemClicked"
            ExpandMode="FullExpandedItem" Height="100%">
            <CollapseAnimation Type="None" Duration="100"></CollapseAnimation>
            <Items>
                <telerik:RadPanelItem runat="server" Text="Places to Go" Font-Bold="true" Font-Size="Medium" Expanded="true" BorderStyle="None">
                    <Items>
                        <telerik:RadPanelItem runat="server" BorderStyle="None">
                            <ItemTemplate>
                                View: &nbsp;&nbsp;&nbsp;
                                <telerik:RadComboBox ID="viewDrop" runat="server" Skin="Web20" Width="100px" MarkFirstMatch="True"
                            Font-Size="12px" EnableVirtualScrolling="True" OnSelectedIndexChanged="viewDrop_SelectedIndexChanged" AutoPostBack="true">
                            <CollapseAnimation Duration="1000" Type="InOutBack" />
                            <Items>
                                <telerik:RadComboBoxItem Value="map" Text="Map" Selected="true" />
                                <telerik:RadComboBoxItem Value="calendar" Text="Calendar" Selected="true" />
                            </Items>
                        </telerik:RadComboBox>
                                <telerik:RadTreeView ID="attractionsTree" runat="server" Skin="Web20" CssClass="leftPanelContent"
                                    CheckBoxes="true" OnClientNodeClicking="OnClientNodeClicking" OnClientNodeChecked="OnClientNodeChecked" >
                                </telerik:RadTreeView>
                            </ItemTemplate>
                        </telerik:RadPanelItem>
                    </Items>
                </telerik:RadPanelItem>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Nov 2009 Link to this post

    Hello,

    Its working fine when I tried the same at my end. From your code, I found that you have mis-spelled the control ID and it's not the same as given in declaration. Could you change the code as shown below and see whether it is working fine?
    Protected Sub viewDrop_SelectedIndexChanged(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) 
     
            Dim dropdown As RadComboBox = DirectCast(RadPanelBar1.FindItemByText("Places to Go").Items(0).FindControl("viewDrop"), RadComboBox)   
           
            If dropdown.SelectedValue = "calendar" Then 
                Response.Redirect("Calendar.aspx"
            End If                 
    End Sub 

    Also you can access the RadComboBox using following approach.
    Protected Sub viewDrop_SelectedIndexChanged(ByVal o As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs) 
        Dim combo As RadComboBox = DirectCast(o, RadComboBox) 
    End Sub 
     

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 24 Nov 2009 Link to this post

    Hello Web Services,

    I guess you have a small typo in the combobox ID:

    <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1">
        </telerik:RadScriptManager>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1"
            Width="220px" Height="520px" BorderStyle="None">
            <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Web20" AllowCollapseAllItems="false"
                Width="220px" BorderStyle="None" _OnClientItemClicked="itemClicked" ExpandMode="FullExpandedItem"
                Height="100%">
                <CollapseAnimation Type="None" Duration="100"></CollapseAnimation>
                <Items>
                    <telerik:RadPanelItem runat="server" Text="Places to Go" Font-Bold="true" Font-Size="Medium"
                        Expanded="true" BorderStyle="None">
                        <Items>
                            <telerik:RadPanelItem runat="server" BorderStyle="None" Value="templateHolder">
                                <ItemTemplate>
                                    View:    
                                    <telerik:RadComboBox ID="viewDrop" runat="server" Skin="Web20" Width="100px" MarkFirstMatch="True"
                                        Font-Size="12px" EnableVirtualScrolling="True" OnSelectedIndexChanged="viewDrop_SelectedIndexChanged"
                                        AutoPostBack="true">
                                        <CollapseAnimation Duration="1000" Type="InOutBack" />
                                        <Items>
                                            <telerik:RadComboBoxItem Value="map" Text="Map" Selected="true" />
                                            <telerik:RadComboBoxItem Value="calendar" Text="Calendar" Selected="true" />
                                        </Items>
                                    </telerik:RadComboBox>
                                    <telerik:RadTreeView ID="attractionsTree" runat="server" Skin="Web20" CssClass="leftPanelContent"
                                        CheckBoxes="true" _OnClientNodeClicking="OnClientNodeClicking" _OnClientNodeChecked="OnClientNodeChecked">
                                    </telerik:RadTreeView>
                                </ItemTemplate>
                            </telerik:RadPanelItem>
                        </Items>
                    </telerik:RadPanelItem>
                </Items>
            </telerik:RadPanelBar>
        </telerik:RadAjaxPanel>
        </form>

    Imports Telerik.Web.UI
     
    Partial Class Default2
        Inherits System.Web.UI.Page
     
        Protected Sub viewDrop_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
            Dim dropdown As RadComboBox = DirectCast(RadPanelBar1.FindItemByText("Places to Go").Items(0).FindControl("viewDrop"), RadComboBox)
     
            If dropdown.SelectedValue = "calendar" Then
                Response.Redirect("Calendar.aspx")
            End If
        End Sub
    End Class


    Best wishes,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 24 Nov 2009 Link to this post

    Sorry for wasting your time. I posted this late in the day yesterday. Thanks,
Back to Top