简体   繁体   English

我在中继器控件上添加了子控件。 该儿童控件未触发该事件

[英]I have added the child controls on repeater control. that child control not firing the event

i have create the wizard control , in side this i have create the repeater control.this repeater control has three radio buttons.all are created with dynamically.I want to fire a radio button checkedchange event. 我已经创建了向导控件,在这边我已经创建了转发器控件。这个转发器控件有三个单选按钮。所有都是动态创建的。我想触发一个单选按钮checkedchange事件。

find the code: 找到代码:

       **Panel objPanel = (Panel)Wizard1.WizardSteps[Wizard1.ActiveStepIndex].Controls[5];
        Repeater reptrAddQuestion = new Repeater();
        reptrAddQuestion.ID = "reptrAddQuestion" + (count-1);
        string[] obj = new string[2];
        reptrAddQuestion.Visible = true;
        reptrAddQuestion.DataSource = obj;
        reptrAddQuestion.DataBind();
        reptrAddQuestion.EnableViewState = true;
        int controlIdValue = (count - 1) + 1;
        for (int index = 0; index <= reptrAddQuestion.Items.Count - 1; index++)
        {
            RadioButton RdoBtn = new RadioButton();
            RdoBtn.AutoPostBack = true;
            RdoBtn.ID = "RdoBtn" + controlIdValue.ToString();
            RdoBtn.CheckedChanged += new System.EventHandler(RdoBtn_CheckedChanged);
            RdoBtn.EnableViewState = true;
            reptrAddQuestion.Controls.Add(RdoBtn);
            controlIdValue += 1;
        }
        objPanel.Visible = true;
        objPanel.Controls.Add(reptrAddQuestion);**

    public void RdoBtn_CheckedChanged(object sender, EventArgs e)
    {

    }

advance thanks for this help. 提前感谢您的帮助。 Regards, Devathidhan.S 此致Devathidhan.S

It depends in which part of the Web Page life cycle you are creating the controls. 这取决于您要在网页生命周期的哪一部分中创建控件。

If you want the controls to handle postbacks and events, you must create them in the pages "OnInit" or "OnPreInit" function. 如果希望控件处理回发和事件,则必须在页面“ OnInit”或“ OnPreInit”函数中创建它们。

If you are creating these controls on Page_Load or later, it's too late. 如果要在Page_Load或更高版本上创建这些控件,则为时已晚。 The controls will not fire events or hold user changes, because by then the postback information has already been processed. 控件将不会触发事件或保留用户更改,因为届时回发信息已被处理。

Try setting the checkbox's AutoPostBack property to true. 尝试将复选框的AutoPostBack属性设置为true。 If that doesn't fix the problem, then it's likely a lifecycle issue, as Andrew said. 如果这不能解决问题,则可能是生命周期问题,如安德鲁所说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM