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

One checked node javascript problem

5 Answers 82 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 24 Feb 2011, 06:13 PM
Hi,

I have a treeview inside a combobox, and i have hooked up a javasript that uncheckes any previus nodes, according to this article,
http://www.telerik.com/help/aspnet/treeview/tree_unchecknodebycheckinganothernode.html

But i cant get the script working, could it be becouse of the treeview being inside of a panelbar and/or a combobox, and if so, would anyone have a solution for this?

<asp:Content ID="Content3" ContentPlaceHolderID="phContent" Runat="Server">
<script type="text/javascript" language="javascript">
   var oldNode;
   function UpdateStatus(node)
   {
       if(oldNode != null)
       {
       oldNode.UnCheck();
       }
       node.Check();
       oldNode = node;
   }
</script>
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
    </telerik:RadAjaxManagerProxy>
      
    <table cellspacing="0" width="100%">
  
<%--
Om man är inloggad som Admin ska man komma direkt till Steg 2
--%>
<tr align="center">
<td align="center" style="padding-top:100px;">
    <telerik:RadPanelBar ID="pbCaseRegistration" Runat="server" Skin="Windows7" 
        Width="500px" ExpandMode="SingleExpandedItem">
        <Items>
              
            <telerik:RadPanelItem runat="server" Text="1 - Ärendeinformation" Expanded="true">
                <Items>
                    <telerik:RadPanelItem runat="server" Value="panCaseinfo">
                        <ItemTemplate>
                            <table class="text" style="padding:10px;" cellspacing=0 width=100%>
                            <tr>
                            <td align=center>
                                <asp:Image ID="imgCaseType" runat="server" ImageUrl="images/infoIcon2.jpg" /><asp:Label ID="Label1" runat="server" Text="Ärendetyp"></asp:Label><br />
                                  
                                       <telerik:RadComboBox ID="cmbCaseType" runat="server" Skin="Windows7" Height="160px" Style="vertical-align: middle;" Width="225px">
                                            <ItemTemplate>
                                                <div id="div1">
                                                  
                                                    <telerik:RadTreeView ID="tvCaseType" runat="server" CheckBoxes="True" 
                                                        Height="160px" Width="100%" AfterClientCheck="UpdateStatus">
                                                          
                                                    </telerik:RadTreeView>

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Feb 2011, 09:48 AM
Hello Christian,

You can use OnClientNodeChecked property instead of AfterClientCheck:

<telerik:RadTreeView ID="tvCaseType" runat="server" CheckBoxes="True"
 OnClientNodeChecked="UpdateStatus">

Thanks,
Princy.
0
Christian
Top achievements
Rank 1
answered on 25 Feb 2011, 11:09 AM
Hello Princy,

thanks for the reply, i did change the event as you said and now the event is fired but i get a error when debugging that says
"Microsoft JScript runtime error: Object doesn't support this property or method"

on this line of code in the javascript

<

 

script type="text/javascript" language="javascript">

 

var oldNode;

function UpdateStatus(node)

{

if(oldNode != null)

{

oldNode.UnCheck();

}

node.Check();      <<<<---- error on this line.

oldNode = node;

}

</

 

script>

 



if i choose continue i still get several checkboxes checked

0
Christian
Top achievements
Rank 1
answered on 25 Feb 2011, 02:33 PM
I managed so solve all my issues using a custom validator script, so i tought i might share it here.

<script type="text/javascript">    
    function ClientValidate(source, arguments) {
         var treeView = document.getElementById("ctl00_phContent_pbCaseRegistration_i0_i0_cmbCaseType_i0_tvCaseType");     
         var checkBoxes = treeView.getElementsByTagName("input");     
         var checkedCount = 0;     
         for (var i = 0; i < checkBoxes.length; i++)
         {       
            if (checkBoxes[i].checked) 
            {         
                checkedCount++;       
            }     
         }     
         if (checkedCount > 0 && checkedCount < 2) 
         {       
         arguments.IsValid = true;     
         
         else 
         {       
         arguments.IsValid = false;     
         }   
     }          
</script>

<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ClientValidate" ErrorMessage="CustomValidator" Display="Dynamic" ValidationGroup="Step1">Vänligen ange En ärendetyp</asp:CustomValidator>

My only concern right now is that i have a radpanel with 3 groups/panels, and in each panel i have a validatorn group thats checked when hitting a "next" button that checks all inputs in the first panel and enables and expands the second panel.

But, when the button is fired it does a postback, leaving all values in the first panel empty again...
So, would anyone know how i can validate a group using a button without doing a postback and enable and expand the second panel?
0
Accepted
Dimitar Terziev
Telerik team
answered on 01 Mar 2011, 05:44 PM
Hi Christian,

Instead of your custom validator, why don't you try the following implementation of the OnClientNodeChecking event handler function:
function OnClientNodeChecking(sender, args) {
     
    sender.uncheckAllNodes();           
}

This way only one node will be checked at a time.

Kind regards,
Dimitar Terziev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Christian
Top achievements
Rank 1
answered on 01 Mar 2011, 06:12 PM
thanks, dont know why i dident think of that one, you just saved my users some cpu load.

If you have any spare time i have some problems at another thread,
http://www.telerik.com/community/forums/aspnet-ajax/panelbar/3-step-panelbar-with-validaton-postback-issues.aspx

Tags
TreeView
Asked by
Christian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Christian
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or