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

RadioButtonList inside template doesn't fire SelectedIndexChanged properly

1 Answer 199 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Thiago
Top achievements
Rank 1
Thiago asked on 13 Feb 2009, 12:23 PM
Hello there,

I'm new with Telerik and my company is evaluating different TreeView components in order to pick one to use. So far you guys are on the lead but I'm struggling with detecting a SelectedIndexChanged detection from a radio button list which is inside a template for all my nodes of the tree view.
Just a bit of background of what I'm doing: I have a tree view that will display the structute of a system where the administrator will setup permissions for each user. So pretty much Each node will represent a system part and each node has the radio button list with the permission options.
My idea is that when a option is changed, this selection would be changed for all child nodes.
I have no limitations to do it at client or server side (althought client side would be prefferable).
So far this is what I have:

<telerik:RadTreeView ID="rtvPermissoes"   
    runat="server" Height="200"   
    onnodedatabound="rtvPermissoes_NodeDataBound"   
    onnodecreated="rtvPermissoes_NodeCreated" onnodeclick="rtvPermissoes_NodeClick">  
    <NodeTemplate> 
        <table cellpadding="0" cellspacing="0" style="width:100%; height:16px;">  
            <tr> 
                <td ID="colNomeEstrutura" style="width:auto;" valign="top">  
                    <asp:Label ID="lblNome" runat="server" Text="">  
                        <%#DataBinder.Eval(Container,"Text") %> 
                    </asp:Label> 
                </td> 
                <td ID="colPermissao" style="width:250px;" valign="top">  
                    <asp:RadioButtonList   
                             ID="optPerm" runat="server" RepeatDirection="Horizontal"   
                             onselectedindexchanged="optPerm_SelectedIndexChanged" > 
                             <asp:ListItem Value="Invisivel">Invisível</asp:ListItem><asp:ListItem Value="SomenteLeitura">Somente Leitura</asp:ListItem><asp:ListItem Value="Escrita">Escrita</asp:ListItem></asp:RadioButtonList></td><td ID="colExpiracao" style="width:100px;" valign="top">  
                    <asp:TextBox ID="txtExp" runat="server" MaxLength="10" Text="" Width="75" /> 
                </td> 
            </tr> 
        </table> 
    </NodeTemplate> 
</telerik:RadTreeView> 

 


I had to declare onnodedatabound and onnodecreated because I was also struggling with the databind to populate by template fields properly, but I got a work around with onnodecreated to make it work. That's probably because I'm populating the treeview nodes after a certain system and user are selected and not on page load, but that's not my main problem right now :)

At code behind I have:

 

        protected void rtvPermissoes_NodeClick(object sender, RadTreeNodeEventArgs e)  
        {  
            RadioButtonList Perm = (RadioButtonList)e.Node.FindControl("optPerm");  
            TextBox Exp = (TextBox)e.Node.FindControl("txtExp");  
            if (Perm.SelectedValue != e.Node.Attributes["Permissao"] ||  
                Exp.Text != e.Node.Attributes["Expiracao"]) //Permissão foi alterada.  
            {  
                AtribuirPermissoesAlteradasAosFilhos(Perm.SelectedValue, Exp.Text, e.Node.Nodes);  
            }  
        }  
 
protected void optPerm_SelectedIndexChanged(object sender, EventArgs e)  
        {  
            RadioButtonList Perm = (RadioButtonList)sender;  
            RadTreeNode node = (RadTreeNode)Perm.Parent;  
            TextBox Exp = (TextBox)node.FindControl("txtExp");  
            if (Perm.SelectedValue != node.Attributes["Permissao"] ||  
                Exp.Text != node.Attributes["Expiracao"]) //Permissão foi alterada.  
            {  
                AtribuirPermissoesAlteradasAosFilhos(Perm.SelectedValue, Exp.Text, node.Nodes);  
            }  
        } 

 

 

 

 

Pretty much the codes are similar and I did it to check when the node click is fired and when the select idenx changed is fired.
Not sure if I will be clear to explain this but while debugging, this routine is not fired when I click at the radio button circle (not the text but right in the circle to select the option), any event is fired at all.
However right after, if I eventually click anywhere in the node it will first fire the selected index changed event and right after node click is fired.
Using this flow I got my goal done. I can determine on which node I'm, I can determine if any setting have been changed (can be the radio button list of the text box as well), and I can call AtribuirPermissoesAlteradasAosFilhos which is a my private method that will loop the child nodes and apply the same selection that the parent node has.
Just as a note when I create the nodes I'm adding to the collection of attributes the selectedValue of the radio button list on Attributes["Permissao"]  and the content of the text box on Attributes["Expiracao"] so I could keep track of it.

My next step was to check what happens when I click on the text of some option on the radio button list. Pretty much the value got selected on the client yet, however the node click event got fired. Debugging it I have found that Perm.SelectedValue had still the old value, so I couldn't retrieve the new value. With this flow the SelectedIndexChangedevent was never fired.

I would like to know if there is any work around in order to get it working.
I'm using Telerik.Web.UI version 2008.3.1314.20

Please let me know if you need more details and sorry for not using english name for methods, I've just copied from my sketch :)
Best regards!

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 16 Feb 2009, 01:50 PM
Hello Thiago,

When you click on the text of the ListItem, the treeview thinks that you have clicked on the text of the node (because it is rendered as label) and fires the NodeClick event. But if you click directly on the radio button - then the SelectedIndexChanged of the radio button list should fire.

I suggest that you set the AutoPostBack property of the RadioButtonList to True and this way the SelectedIndexChanged will fire every time. So, you can put your logic in that event only.

Let us know if you have more questions.

Regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
Thiago
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or