ASP单选按钮oncheckedchange不触发

本文关键字:oncheckedchange 单选按钮 ASP | 更新日期: 2023-09-27 18:17:01

我有一个自定义的单选按钮下面的一个中继器,当用户点击它,它应该触发后面的代码,但这并没有发射。我在方法的开始处设置了一个断点,它永远不会到达。唯一发生的事情是回发updatepanel

<EclipseUI:CustomRadioButton runat="server" ID="RadioButton_Select"
                                            ClientIDMode="AutoID" ToolTip='<%# "id_" + Eval("FeaturePackId") %>' GroupName='<%# "id_" + Eval("FeaturePackId") %>'
                                            OnCheckedChanged="RadioButton_Select_OnCheckedChanged" AutoPostBack="True"/>

后面的代码很简单,它获取每个选中的单选按钮的值,并将其放置在一个隐藏字段中以供以后使用。

protected void RadioButton_Select_OnCheckedChanged(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        sb.Clear();
        foreach (RepeaterItem repeaterItem in Repeater_Select.Items)
        {
            CustomRadioButton radioButton = repeaterItem.FindControl("RadioButton_Select") as CustomRadioButton;
            if (radioButton != null)
            {
                if (radioButton.Checked)
                {
                    sb.Append(radioButton.GroupName.Substring(4));
                }
                else
                {
                    sb.Replace(radioButton.GroupName.Substring(4), "");
                }
            }
        }
        HF_Feature.Value = sb.ToString();
    }

我的问题是这个根本不启动。

编辑

我的代码现在如下所示,项目绑定事件被击中,事件处理程序的+=赋值给单选按钮,但单击单选按钮仍然没有击中我的断点在单选按钮方法的OnCheckedChange:

protected void Page_Load(object sender, EventArgs e)
    {
        Repeater_Select.ItemDataBound += new RepeaterItemEventHandler(Repeater_Select_OnItemDataBound);
    }
protected void Repeater_Select_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            CustomRadioButton customRbtn = (CustomRadioButton)e.Item.FindControl("RadioButton_Select");
            customRbtn.CheckedChanged += new EventHandler(RadioButton_Select_OnCheckedChanged);
        }
    }

但是还是不行

ASP单选按钮oncheckedchange不触发

在repeaters中,你必须在repeaters _ItemDataBound中连接OnCheckedChanged事件。

 protected void Page_Init(object sender, EventArgs e
{
   myRepeater.ItemDataBound += new RepeaterItemEventHandler(myRepeater_ItemDataBound);
}

然后. .

private void myRepeater_ItemDataBound(object sender, RepeaterCommandEventArgs e)
{
    if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType !=
       ListItemType.AlternatingItem)
    {
        CustomRadioButton customRbtn = (CustomRadioButton)e.Item.FindControl("RadioButton_Select");
        //Now you have an instance of your eclipse radio button so you can do what you want with it.
    }
}

看看这个:asp:checkbox的OnCheckedChanged事件处理程序不会在checkbox未选中时触发"_ItemDataBound"被连接起来。

如果您在.aspx文件中使用项目模板,则

和本文可能更接近您的问题。http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065/ASPNET-Tip-Use-the-ItemDataBound-Event-of-a-Repeater.htm

尝试设置CauseValidation="false"(除了Autopostback="true")

<EclipseUI:CustomRadioButton runat="server" ID="RadioButton_Select" ClientIDMode="AutoID" ToolTip='<%# "id_" + Eval("FeaturePackId") %>' GroupName='<%# "id_" + Eval("FeaturePackId") %>' OnCheckedChanged="RadioButton_Select_OnCheckedChanged" AutoPostBack="True" CauseValidation="false"/>

它是…