Fail to find combo

5 posts, 1 answers
  1. Regula
    Regula avatar
    43 posts
    Member since:
    Sep 2005

    Posted 24 May 2011 Link to this post

    Hi,

    I have this piece of code:



    <script type="text/javascript">
     
     
           function setEmpty()
            {
                var combo = $find("<%= combo1.ClientID %>");
                combo.clearselection(); 
                combo.set_emptyMessage("select please"); 
            }
     
     
            function nodeClicking(sender, args) {
                var comboBox = $find("<%= combo1.ClientID %>");
     
                var node = args.get_node()
                comboBox.set_text(node.get_text());
     
                comboBox.trackChanges();
                comboBox.get_items().getItem(0).set_text(node.get_text());
                comboBox.get_items().getItem(0).set_value(node.get_value());
     
                comboBox.commitChanges();
     
                comboBox.hideDropDown();
     
                // Call comboBox.attachDropDown if:
                // 1) The RadComboBox is inside an AJAX panel.
                // 2) The RadTreeView has a server-side event handler for the NodeClick event, i.e. it initiates a postback when clicking on a Node.
                // Otherwise the AJAX postback becomes a normal postback regardless of the outer AJAX panel.
     
                //comboBox.attachDropDown();
            }
     
            function StopPropagation(e) {
                if (!e) {
                    e = window.event;
                }
     
                e.cancelBubble = true;
            }
     
            function OnClientDropDownOpenedHandler(sender, eventArgs) {
                var tree = sender.get_items().getItem(0).findControl("rvt1");
                var selectedNode = tree.get_selectedNode();
                if (selectedNode) {
                    selectedNode.scrollIntoView();
                }
            }
        </script>
     
     
    <telerik:RadComboBox ID="combo1" runat="server" CausesValidation="false"
        EnableEmbeddedSkins="false" OnClientDropDownOpened="OnClientDropDownOpenedHandler"
        EmptyMessage="select please" MaxHeight="200px"  ShowToggleImage="True" 
     
        Width="50%" AllowCustomText="True">
        <ItemTemplate>
            <div id="div1">
                <telerik:RadTreeView ID="rvt1" runat="server" Width="100%" Height="250px"
                    DataSourceID="ds1" DataFieldID="ID" DataValueField="ID"
                    DataFieldParentID="ParentID" DataTextField="Name" OnClientNodeClicking="nodeClicking" >
                    <DataBindings>
                        <telerik:RadTreeNodeBinding Expanded="true" />
                    </DataBindings>
                </telerik:RadTreeView>
            </div>
        </ItemTemplate>
        <Items>
            <telerik:RadComboBoxItem Text="" />
        </Items>
    </telerik:RadComboBox>
    <asp:ObjectDataSource ID="ds2" runat="server"
        EnablePaging="True" OnSelecting="dds2_Selecting"
        SelectMethod="GetList" TypeName="BLL">
        <SelectParameters>
            <asp:Parameter Name="p1" Type="Int32" />
            <asp:Parameter Name="p2" Type="Int32" />
            <asp:Parameter Name="p3" Type="Boolean"  DefaultValue="True" />
        </SelectParameters>
    </asp:ObjectDataSource>



    The combobox is inside a panel. When I show the panel, I call the function setEmpty() to clear the previous data. The problem is that I get a javascript exception. Debugging, I realize that the that the find("<%combo1.ClientID %>"); is returning null... ie it is not able to find the combo1.ClientID. The strange thing is that the function nodeClicking is working, ie, when I click in a node, the nodeClicking function is properly executed... The only problem is with tje setEmpty() function.


  2. Answer
    Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 24 May 2011 Link to this post

    Hi Regula,

    Your code looks alright to me. It's not complete so I can't be sure of exactly what is going wrong, but I think I have an idea. The $find command is used correctly so it should find the control if it exists. That implies to me that the RadComboBox doesn't exist when the code is executed. If the RadComboBox is inside a panel, and you call the setEmpty() function from the panel, the RadComboBox may not exist yet. I would wire-up the OnClientLoad event of the RadComboBox to do the logic in the setEmpty() function.

    Here's a useful document:
    http://www.telerik.com/help/aspnet-ajax/combobox-onclientload.html

    Hope this helps,
    -Gimmik
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Regula
    Regula avatar
    43 posts
    Member since:
    Sep 2005

    Posted 25 May 2011 Link to this post

    Thanks Gimmik

    I followed your suggestion. Now I'm running in another problem.

    I've set the
    combo1.OnClientLoad = "setEmpty";

    And changed the setEmpty to:

       function setEmpty(sender)
            {
                var combo = sender;
                combo.clearselection();  
                combo.set_emptyMessage("Escolha uma rubrica pai");  
            }


    Now var combo gets the combo objecto but it fails to call the clearselection() method. It returns the undefined function error. Can you guess we the clearfuntion is not available?
  5. Regula
    Regula avatar
    43 posts
    Member since:
    Sep 2005

    Posted 25 May 2011 Link to this post

    Never mind Gimmik...

    I was calling clearselection instead of clearSelection (S case....)

    Thanks again Gimmik.

  6. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 25 May 2011 Link to this post

    It's always the simple things that we miss Regula.

    I'm glad it's working for you.
    -Gimmik
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017