在类约会模板内的链接按钮上设置事件处理程序不会触发

时间:2018-05-01 08:19:08

标签: c# asp.net webforms telerik

我有一个telerik RadScheduler控件,我正在创建一个自定义约会模板。模板成功绑定,但是我的模板内部是一个链接按钮,我想将事件绑定到。我可以看到事件绑定,但它不调用代码并点击response.redirect,而是页面刷新,约会模板消失。如何在按钮单击时正确处理事件? apptemplate将附加在页面加载上。

public class AppTemplate : ITemplate
        {
            public void InstantiateIn(Control container)
            {
                SchedulerAppointmentContainer aptCont = (SchedulerAppointmentContainer)container;
                Appointment app = aptCont.Appointment;
            LinkButton lbs = new LinkButton();
            lbs.ID = "btnConductAppointment";
            lbs.Text = "<div style=\"font-weight:bold;\">" + app.Attributes["ApptClientID"] + "</div><div>" + app.Attributes["Title"] + " " + app.Attributes["Surname"] + "</div>";



            //nlbs.Click += btnConductAppointment_Click;
            lbs.DataBinding += new EventHandler(label1_DataBinding);
            lbs.CausesValidation = false;



            container.Controls.Add(lbs);
        }

        private void label1_DataBinding(object sender, EventArgs e)
        {
            LinkButton target = (LinkButton)sender;
            target.Click += new EventHandler(btnConductAppointment_Click);
        }

        protected  void btnConductAppointment_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Response.Redirect(PageDirectory.Default, true);
        }
    }

1 个答案:

答案 0 :(得分:0)

将绑定放在PageInit上意味着事件始终存在。

protected override void OnInit(EventArgs e)
{
   RadScheduler1.AppointmentTemplate = new AppTemplate();
}