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

Can't get Combobox Object

3 Answers 61 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Web Services
Top achievements
Rank 2
Web Services asked on 23 Nov 2009, 11:25 PM
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>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Nov 2009, 08:07 AM
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.
0
Paul
Telerik team
answered on 24 Nov 2009, 08:14 AM
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.
0
Web Services
Top achievements
Rank 2
answered on 24 Nov 2009, 02:28 PM
Sorry for wasting your time. I posted this late in the day yesterday. Thanks,
Tags
ComboBox
Asked by
Web Services
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Paul
Telerik team
Web Services
Top achievements
Rank 2
Share this question
or