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

NodeCreated event always fires

1 Answer 51 Views
This is a migrated thread and some comments may be shown as answers.
David zhao
Top achievements
Rank 1
David zhao asked on 15 Jun 2010, 10:45 AM
I am using RadControls for ASP.NET AJAX Q1 2010 SP2  v2010.1.519.35.

The aspx file includes:
[.aspx begin]
<telerik:RadTreeView ID="RadTreeView1" Runat="server" onnodecreated="RadTreeView1_NodeCreated">

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="AddNode" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Other" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
         <telerik:AjaxSetting AjaxControlID="Button1">
                 <telerik:AjaxUpdatedControl ControlID="RadTreeView1" />
<telerik:RadScriptManager ID="RadScriptManager1" Runat="server"></telerik:RadScriptManager>
[.aspx end]

the c# codes behind are:
[c# begin]
private static int i = 0;

protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)
    RadTreeNode node = new RadTreeNode();
    node.Value = i.ToString();

protected void RadTreeView1_NodeCreated(object sender, RadTreeNodeEventArgs e)
    if( e.Node.Level == 0)
        e.Node.Text = "No." + i.ToString();

protected void Button2_Click(object sender, EventArgs e)
    int j = 0;
[c# end]

My intention is:
        add RadTreeView nodes by pressing button1 ,control the nods by NodeCreated event;
        do something else by pressing button2.

My problem is:
        when pressing the "Button2", the NodeCreated event for RadTreeView1 is also fired . We can see it from the changing of "i" variable.

Why? Or how to avoid it?


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 15 Jun 2010, 11:35 AM
Hi David zhao,

The ItemCreated event fires on each postback because the Nodes of the TreeView are re-created on each postback.

I suggest you increase the i-counter and set the text of the Node in the Button1_Click event handler when you are actually adding the Node.

the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Asked by
David zhao
Top achievements
Rank 1
Answers by
Telerik team
Share this question