Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:09:03+00:00 2026-05-29T04:09:03+00:00

I have a control that contains a javascript function that is called on the

  • 0

I have a control that contains a javascript function that is called on the client click event of a button:

OnClientClicked="ClearTree" 

the function:

    function ClearTree() {
        var tree = $find('<%=cboOrgUnits.Items[0].FindControl("tvOrgUnits").ClientID %>');
        var nodes = tree.get_nodes();
        for (var i = 0; i < nodes.get_count(); i++) {
            nodes.getNode(i).uncheck();
        }
   };

Which all works fine except for when the control is on the same page twice. When it is there are 2 instances of the function ‘ClearTree’ of which it seems the second one added is always called.

The problem is that the instance of ClearTree() called might not be referencing the correct tree.

What are the possible workarounds for this?

Here is the rest of the markup:

<telerik:RadComboBox ID="cboOrgUnits" runat="server" Width="400px" ShowToggleImage="True" Style="vertical-align: middle;" EmptyMessage="Choose organisation units to group by" ExpandAnimation-Type="None" CollapseAnimation-Type="None">
<HeaderTemplate>
    <div>
        <span class="right" style="margin:2px"><telerik:RadButton ID="rbClear" runat="server" Text="Clear" Visible="True" OnClientClicked="ClearTree" AutoPostBack="False"/></span>
        <span class="right" style="margin:2px"><telerik:RadButton ID="rbDone" runat="server" Text="Done" Visible="True" OnClick="rbDone_Click"/></span>
        <div class="clear"></div>
    </div>
</HeaderTemplate>
<ItemTemplate>
    <div>
        <telerik:RadTreeView ID="tvOrgUnits" runat="server" CheckBoxes="true" Style="z-index: 100" CheckChildNodes="True">
            <Nodes>
            </Nodes>
        </telerik:RadTreeView>
    </div>
</ItemTemplate>
<Items>
    <telerik:RadComboBoxItem Text="" />
</Items>
</telerik:RadComboBox>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:09:04+00:00Added an answer on May 29, 2026 at 4:09 am

    Instead of embedding the ClientID of the control inside your function, make it a function parameter, and then change your OnClientClicked to pass the ClientID to the function.

    function ClearTree(id)
    {
        var tree = $find(id);
        // ...
    }
    
    protected override void Render(HtmlTextWriter writer)
    {
        rbClear.OnClientClicked = String.Format("ClearTree('{0}')", rbClear.ClientID);
        base.Render(writer);
    }
    

    UPDATE: Because rbClear is defined inside a template, you might need to call cboOrgUnits.FindControl("rbClear") to get a reference to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Button control that contains an Image object as its content.
I have a custom user control (ascx) that contains a textbox and a Javascript-based
I have a masterpage that contains all the javascript and inside the content control,
I have a composite control that contains a ListBox child control. On postback, the
I have a repeater control that contains an ItemTemplate containing a databound label and
I have a user control that contains a collection of controls to be reused
I have a user control that contains a GridView. The GridView has both a
I have a web user control that contains several other (web user) controls and
I have a custom user control that contains asp:ValidationSummary . It is placed on
I have a list box control that contains enough items to list them with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.