Button Click in ItemTemplate not firing on first click

5 posts, 0 answers
  1. Dean
    Dean avatar
    3 posts
    Member since:
    Mar 2011

    Posted 06 Jan 2012 Link to this post

    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;
            }
        }
    }


  2. Dean
    Dean avatar
    3 posts
    Member since:
    Mar 2011

    Posted 06 Jan 2012 Link to this post

    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. 
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dean
    Dean avatar
    3 posts
    Member since:
    Mar 2011

    Posted 06 Jan 2012 Link to this post

    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);      
    }
  5. Scott
    Scott avatar
    6 posts
    Member since:
    Mar 2012

    Posted 17 Apr 2012 Link to this post

    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
  6. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 20 Apr 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017