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

Button Click in ItemTemplate not firing on first click

4 Answers 249 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 1
Dean asked on 06 Jan 2012, 08:03 PM
I am trying to make the nodes clickable so that I can do something when they are clicked. I am doing simple manual binding using a  list of objects. I am only binding one level at a time because of how deep our heirarchy can be. So when they click on the node I will bind the level below that person. I have a button inside an item template. After the nodes render, I click on the button and it does a post back but does not fire the button click event. If I click it a second time it does a postback and DOES fire the button click event. I have also tried to handle the GroupItemDataBound to use the FindControl you introduced in SP1 with the hopes of attaching the event there instead of the markup as I am doing below. How ever FindControl("LinkButtonNode") returned null. Please advise as I have not run into this before. Or if you know a better way to make the node clickable please advise.

Markup:

<telerik:RadOrgChart ID="RadOrgChartDirectReports1" EnableViewState="true" Skin="Office2010Silver"
           runat="server">
           <ItemTemplate>  
               <asp:Button CausesValidation = "false" OnClick="LinkButton_Click" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeId")%>'
                   runat="server" Text = "Click" ID="LinkButtonNode"></asp:Button>
           </ItemTemplate>
           
       </telerik:RadOrgChart>


Code behind:

private void BindOrgChart2()
   {
       RadOrgChartDirectReports1.DataSource = DataAccess.GetNewHireList();         
       RadOrgChartDirectReports1.DataBind();
   }

public void LinkButton_Click(object sender, EventArgs e)
   {
       string test = "";
   }


DataAccess:

namespace RadControlsTestWebApp1
{
    public class DataAccess
    {
        public static List<HeirarchyBind> GetNewHireList()
        {
            var list = new List<NewHireNotification>();
            using (var client = new RadControlsTestWebApp1.EmployeeService.NewHireNotificationClient())
            {
                list = client.GetEmployeeNewHireNotifications(null);
            }
 
            var newlist = list.Select(x => new HeirarchyBind
            {
                Name = string.Format("{0} '{1}' {2}", x.HireInformation.FirstName, x.HireInformation.PreferredName, x.HireInformation.LastName),
                EmployeeId = x.HireInformation.EmployeeId,
            }).ToList();
 
            return newlist;
        }
    }
}


4 Answers, 1 is accepted

Sort by
0
Dean
Top achievements
Rank 1
answered on 06 Jan 2012, 08:30 PM
Some more information. I am binding on every page load instead of non post backs. Because I guess you guys are not using view state to recreate it on postbacks? I marked the EnabledViewState = true but it still disappears on postback. 
0
Dean
Top achievements
Rank 1
answered on 06 Jan 2012, 10:23 PM
UPDATE: 

I figured out a work around. If I force the template to reload in page init like below it works. Now sure why. 

protected override void OnInit(EventArgs e)
{      
    base.OnInit(e);       
    RadOrgChartDirectReports1.ItemTemplate.InstantiateIn(RadOrgChartDirectReports1);      
}
0
Scott
Top achievements
Rank 2
answered on 17 Apr 2012, 08:31 AM
I have a similar problem, I tried your solution but it has not seemed to work for me


this is what I'm using oninit


    Protected Overrides Sub OnInit(e As EventArgs)
        MyBase.OnInit(e)
        Try
            BindToIEnumerable(RadOrgChart1)
            RadOrgChart1.DataBind()
        Catch ex As Exception

        End Try
    End Sub
0
Peter Filipov
Telerik team
answered on 20 Apr 2012, 11:22 AM
Hello,

The mentioned issues are fixed in the latest version of our controls - Q1.2012 Service pack 1. Could you please try to apply the newest DLLs and test your project.
In case that you still have problems with the events, please open a support ticket and send me your project for a local test.

All the best,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
OrgChart
Asked by
Dean
Top achievements
Rank 1
Answers by
Dean
Top achievements
Rank 1
Scott
Top achievements
Rank 2
Peter Filipov
Telerik team
Share this question
or