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

[Solved] radTreeNode Controls added an asp.net Button, the buttonclick event does not fired

13 Answers 348 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
calai
Top achievements
Rank 2
calai asked on 05 Dec 2008, 08:15 AM
Hello there again,

In our rad tree node we added an asp.net button control, but whenever we click the button, it's buttonclick event does not fired but instead the nodeclick event is fired.

Maybe you can help me also in this one.

Hope to hear from you soon.

Thank you.

Greetings,

~cLyde~

^_^

13 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 05 Dec 2008, 08:39 AM
Hello clyde rose,

We just tested this with Telerik.Web.UI v2008.3.1125 and it worked normally, e.g. clicking the Button in the Template did not fire the NodeClick event.

Could you please verify which version you are using?

In case yours is older, please upgrade.

Greetings,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
calai
Top achievements
Rank 2
answered on 08 Dec 2008, 03:21 AM
Hello Simon,

Just replied now, since i have tried your recommendation. Yes, i have upgraded my control to Q3 2008 as what you have said. But still the button click event is not fired back instead the node click event of the rad tree node.

I guess maybe a reason could be that i have installed two Telerik controls, the previous one i have, Q2 2008 and the latest you have suggested, Q3. As i have observed in my VS application the previous version is not overwritten instead a new group of controls were made upon installation the Q3, do you think it conflicts with the previous Q2 control? Do i have to uninstall my previous version of Telerik control before i Install a new one? Does it not update your previous version upon installing the latest version? Because I don't find any cause of my problem, since you've said that it does work fine with your latest control, Q3.

Thank you.

Greetings,

~cLyde~

^_^
0
Atanas Korchev
Telerik team
answered on 08 Dec 2008, 01:29 PM
Hello clyde rose,

Please find attached a sample web site which works as expected on my end. What is different at your side?

Sincerely yours,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
calai
Top achievements
Rank 2
answered on 09 Dec 2008, 02:19 AM
Hello Albert,

The difference with our application is that we created the button dynamically, and added it to the node with the use of
"node.controls.add(the_control)" .

Thank you.

Greetings,

~cLyde~

^_^
0
Accepted
Atanas Korchev
Telerik team
answered on 09 Dec 2008, 11:43 AM
Hello clyde rose,

I have attached a modified sample project which demonstrates the required approach. I have also commented the code to explain the interesting spots.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
calai
Top achievements
Rank 2
answered on 10 Dec 2008, 03:28 AM
Hi Albert,

In our case we just used the RadTreeView FindNodeByValue(newNode.value). And then add the Button control on the newNode.
And it does not fire back the button click.

While in your case you added the button control on the RadTreeView using the radtreeview1.node(index).nodes(inde).controls.add.

Thank you.

Greetings,

~cLyde~

^_^
0
calai
Top achievements
Rank 2
answered on 10 Dec 2008, 06:31 AM
Hello Albert,

Thanks a lot for your help, I have solved the problem now.

Keep up the good work.

Best Regards,

~cLyde~

^_^
0
Andy
Top achievements
Rank 1
answered on 02 Dec 2009, 02:58 PM
Hi,
We are having the same problem. Nothing is firing. Have tried setting
cb.AutoPostPack = true without luck either.

protected void RadTreeView_NodeCheck(object sender, RadTreeNodeEventArgs e)   
{   
 
 if(e.Node.Checked)   
 {  
  CheckBox cb = new CheckBox();   
  cb.Checked = false;  
  //cb.AutoPostBack = true;   
  cb.CheckedChanged += new EventHandler(CheckBox_CheckedChanged);   
  e.Node.Controls.Add(cb);  
 }  
}  
 
public void CheckBox_CheckedChanged(object sender, EventArgs e)   
{  
CheckBox cb = (CheckBox)sender; //In debug this event is not fired.   

I would assume you need to register the events on the Page_Load event?

Any hints? Your example obviously works but wondering why ours wouldnt...

Thanks in advance
Andy

 

 

0
Ed
Top achievements
Rank 1
answered on 08 Dec 2009, 06:19 PM
Hi there,

I realise this post is a year old but I am having a similar problem: I am adding some new nodes via load-on-demand that contain a LinkButton control with a handler for the OnClick event:

       private void LoadOnDemand(object sender, RadTreeNodeEventArgs e
        { 
            RadTreeNode nodeSurvey = e.Node;
            RadTreeNode nodeViewQuestions = new RadTreeNode(); 
            LinkButton lb = new LinkButton(); 
            lb.Text = "temp title"
            lb.Click += new EventHandler(ViewQuestions); 
            nodeViewQuestions.Controls.Add(lb); 
            nodeViewQuestions.PostBack = true
            nodeSurvey.Nodes.Add(nodeViewQuestions); 
        } 
 
        protected void ViewQuestions(object sender, EventArgs e) 
        { 
            Response.Redirect("www.liverpoolfc.tv"); 
        } 
 

The node appears to be correctly loaded on-demand after its parent is expanded; however, clicking the link button does not have the desired effect.  Note that I have *not* set a global handler for OnNodeClick as no other nodes require it.

All help gratefully received -- I'm getting desperate!

Ed Graham
0
Andy
Top achievements
Rank 1
answered on 08 Dec 2009, 07:27 PM
Hi Ed,
The below should work for you - this is the same response from Telerik.

Page_Load()
{
 if(!Page.IsPostback)
 {
     //load your tree as usual
 }
foreach(RadTreeNode node in RadTreeTest1.GetAllNodes())
{
 if(node.Attributes["added"] == "linkbutton")
  (
    AddLinkButton(node); //you need to reload the button
  )
}
}

private void AddLinkButton(RadTreeNode node)
{
LinkButton lb = new LinkButton(); 
lb.Text = "temp title"
lb.Click += new EventHandler(ViewQuestions);
node.Attributes.Add["added"] = "linkbutton";
}

private void LoadOnDemand(object sender, RadTreeNodeEventArgs e
        { 
            RadTreeNode nodeSurvey = e.Node;
            RadTreeNode nodeViewQuestions = new RadTreeNode(); 
               
        
             
            nodeViewQuestions.Controls.Add(AddLinkButton(nodeViewQuestions)); 
            //nodeViewQuestions.PostBack = true;  //not sure if you will need this?
            nodeSurvey.Nodes.Add(nodeViewQuestions); 
        } 
 
        protected void ViewQuestions(object sender, EventArgs e) 
        { 
            Response.Redirect("www.liverpoolfc.tv"); 
        }
0
Ed
Top achievements
Rank 1
answered on 10 Dec 2009, 10:41 AM
Thanks a lot for the response, Andy; much appreciated.  I understand your solution and agree that it should have worked ... but it didn't!  I followed your implementation to the letter but upon posting back the nodes simply don't have the "added" attribute; hence "AddLinkButton()" is not called and the link buttons are not reinstated.  I wonder if it's because I'm using server-side callbacks; i.e. the parent nodes have

node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack

Telerik?  Any ideas?

0
Andy
Top achievements
Rank 1
answered on 11 Dec 2009, 01:38 PM
Hi Ed,

Yes I gave up on using TreeNodeExpandMode.ServerSideCallBack and instead used TreeNodeExpandMode.ServerSide. It
was a real fiddle to get it to work but its working now.  The trick is to remove the ["added"] attribute on Node_Click and only
apply the attribute to the node that you are loading - thats if you have multiple nodes in the tree where you want to apply the link button dynamically. Also note that on postback you will find there are two link buttons (or two controls) if you are not careful to ensure the attriute is removed on Node_Click.  I ended up setting the visiblity to false and then enabling it again in the AddLinkButton routine. e.g. node.Controls[0].Visible = true;

For some reason even if the child control is not even present, the visibilty is still preserved, must in the ViewState or tucked away in the AJAX or possibly a bug - you wouldnt expect a Control that doesnt even exist to remember its visibility or not - so you need to re-enable it. Its a fiddle to get this to work as expected which is a shame - not Teleriks fault - just the problem really with Dynamic controls in general not being registered with the page as the child events are not bubbled as expected.

It would be nice wouldnt when loading dynamic controls that we just had:
Controls.Add(child);
child.Register();  :) and be able to get on with it.

The behaviour I noticed was that the state was not the most up to date state of the on post back when using ServerSideCallBack.
You can test that by setting a node to be in the Inderminate state but will still be checked by the time you are calling the Node_Click event.

We actually have multiple Trees in this particular control, with some needing to have dynamic controls loaded at runtime and others not - you can imagine the fun -  and then used the below for any postbacks which at least smooths out the experience.

We also have this control in the RadPageView which beware loads all the controls in each of the RadPageViews no matter what you do - even if you programitically remove the control from the RadPageView the control still executes - we are working around this now by setting testing the visibility state of the control on each load where we have controls for each RadPageView - not perfect but
I guess sometimes we just have to find workarounds.

Use this to make things nicer:
 <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1">
     </telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadTabStrip1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                        <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadMultiPage1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>


Heres some reworked code for you:
 protected void AddCheckBox(RadTreeNode node)  
        {  
            Literal version = new Literal();  
            version.Text = node.Text;  
            CheckBox cbxAndAbove = new CheckBox();  
 
            cbxAndAbove.Text = node.ParentNode.Attributes["OrAbove"];  
 
            cbxAndAbove.AutoPostBack = true;  
            cbxAndAbove.Attributes.Add("nodevalue", node.Value);  
 
 
            if (node.Attributes["loading"] != null)  
            {  
                cbxAndAbove.Checked = true;  
 
                foreach (RadTreeNode childNode in node.ParentNode.Nodes)  
                {  
                    if (childNode.Index > node.Index)  
                    {  
                        childNode.Enabled = false;  
                    }  
                }  
            }  
 
            cbxAndAbove.CheckedChanged += new EventHandler(cbxAndAbove_CheckedChanged);  
 
            node.Controls.Add(version);  
            node.Controls.Add(cbxAndAbove);  
            node.Controls[1].Visible = true; //reenable the visibilty as lost (even though no controls!)  
 
            node.Attributes.Add("added", "checkbox");  
 
            node.Selected = false;  
 
        } 

Note to also remove the "loading" attribute on node click as this is only required when getting your values from your datasource.

All the best,
Andy
0
Ed
Top achievements
Rank 1
answered on 11 Dec 2009, 04:58 PM
Gosh -- what an answer!  That's fantastically community-spirited of you Andy: thanks very much again, and happy Christmas.  I think if anything your travails have warned me to look for another approach!  I'll play around with the code you sent, though, as it would be nice to do this neatly if possible.

Thanks again,

Ed
Tags
TreeView
Asked by
calai
Top achievements
Rank 2
Answers by
Simon
Telerik team
calai
Top achievements
Rank 2
Atanas Korchev
Telerik team
Andy
Top achievements
Rank 1
Ed
Top achievements
Rank 1
Share this question
or