简体   繁体   中英

ASP Radiobutton oncheckedchange not firing

I have a custom radiobutton below inside of a repeater and when a user clicks it, it is supposed to fire the code behind, however this is not firing at all. I've placed a breakpoint at the beginning of the method and it isnt ever reached. The only thing that does happen is a postback of the updatepanel

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

The code behind is simply this, it takes the value of each checked radiobutton and places it in a hidden field for use later.

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

My problem is that this doesnt fire at all.

EDIT

My code is now as follows, and the item databound event is hit and so is the += assignment of the eventhandler to the radiobutton but clicking the radiobutton still doesnt hit my breakpoint in the OnCheckedChange of the radiobutton method:

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

But it is still not working

in a repeater you will have to wire up the OnCheckedChanged events inside of the repeaters _ItemDataBound.

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

and then..

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.

    }
}

Have a looksy at this: OnCheckedChanged event handler of asp:checkbox does not fire when checkbox is unchecked at at way the "_ItemDataBound" is wired up.

and this article may be a little closer to your problem if your using item template in the .aspx file. http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c12065/ASPNET-Tip-Use-the-ItemDataBound-Event-of-a-Repeater.htm

Just try to setting CauseValidation="false" (besides 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"/>

It works...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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