1

I have a radiobutton control dynamically generated inside of a repeater. On this radiobutton I am calling OnCheckChanged to change some value in the code behind on checking on the radiobutton.

<EclipseUI:CustomRadioButton ID="RadioButton_Selected" runat="server" GroupName='<%# "s_id_" + Eval("FeaturePackId") %>' 
 OnCheckedChanged="RadioButton_Selected_OnCheckedChanged"/>

My Radiobuttonis above and calls the shown method.

If it makes any difference the radiobutton is being checked and unchecked by jquery code on a div click.

protected void RadioButton_Selected_OnCheckedChanged(object sender, EventArgs e)
{
    CustomRadioButton rb = (CustomRadioButton) sender;
    System.Diagnostics.Debug.WriteLine(rb.GroupName);
    int FeatureID = Int32.Parse(rb.GroupName.Remove(0, 4));

    if (rb.Checked)
    {
        FeatureList.Add(FeatureID);
    }
    if (!rb.Checked)
    {
        foreach (var itemToRemove in FeatureList)
        {
            FeatureList.Remove(itemToRemove);
            System.Diagnostics.Debug.WriteLine(itemToRemove);
        }
    }
}

public List<int> FeatureList = new List<int>();

This code basically adds of subsracts the value on the radiobuttonto the List of ints. However this method is not being called at all. I have tried placing the debug writeline statements but these do not output anything to the output window.

Does anyone know why this method is not firing?

user667430
  • 1,487
  • 8
  • 38
  • 73

2 Answers2

1

Try this first because its easy.

Similar question here: OnCheckedChanged event not firing

There are two differences from the posted answer to yours: Enabled="true" AutoPostBack="true"

But since you tried this already I really think it is more likely because you are creating your elements in the wrong place in the page lifecycle (timewise too early) at the pre-page rendering so you may want to create the method binding in the pageload in the non-postback.

In short you have the method and the button but they are not bound to each other.

I am not sure this code will work 'as is', but it might give you some ideas.

    if (!Page.IsPostBack)
      {
         CustomRadioButton rb = (CustomRadioButton)e.Item.FindControl("CustomRadioButtonID");
         rb.OnCheckedChanged += new EventHandler(RadioButton_Selected_OnCheckedChanged);
      }
Community
  • 1
  • 1
JPK
  • 1,324
  • 2
  • 14
  • 25
-1

I think you should set the PostBack property to TRUE on your CustomRadioButton control.

karim
  • 164
  • 7