2

C# で 2 つのラジオ ボタンを動的に作成していますが、CheckedChange イベントが発生しません。次のコードを使用しています。

RadioButton enable = new RadioButton();
enable.ID = "enable";
enable.Text = "Enable";
enable.GroupName = "enableDisableGroup";
enable.CheckedChanged += new EventHandler(enableRadioButton_CheckedChanged);

RadioButton disable = new RadioButton();
disable.ID = "disable";
disable.Text = "Disable";
disable.GroupName = "enableDisableGroup";
disable.CheckedChanged += new EventHandler(disableRadioButton_CheckedChanged);

UpdatePanel upEnableDisable = new UpdatePanel();
upEnableDisable.UpdateMode = UpdatePanelUpdateMode.Conditional;
upEnableDisable.ContentTemplateContainer.Controls.Add(enable);
upEnableDisable.ContentTemplateContainer.Controls.Add(disable);

AsyncPostBackTrigger enableTrigger = new AsyncPostBackTrigger();
enableTrigger.ControlID = enable.ID;
enableTrigger.EventName = "CheckedChanged";
upEnableDisable.Triggers.Add(enableTrigger);
AsyncPostBackTrigger disableTrigger = new AsyncPostBackTrigger();
disableTrigger.ControlID = disable.ID;
disableTrigger.EventName = "CheckedChanged";
upEnableDisable.Triggers.Add(disableTrigger);

mainDiv.Controls.Add(upEnableDisable);

ラジオ ボタンを作成したら、Checked Changedイベントを関連付けます。次に、これらを UpdatePanel 内に配置します。私も 2 つAsyncPostBackTriggerの を作成しようとしましたが、それもうまくいきませんでした。上記のコード スニペットの問題点を教えてください。

4

1 に答える 1

2
RadioButton enable = new RadioButton();
enable.ID = "enable";
enable.Text = "Enable";
enable.AutoPostBack = true;
enable.GroupName = "enableDisableGroup";
enable.CheckedChanged += new EventHandler(enableRadioButton_CheckedChanged);

RadioButton disable = new RadioButton();
disable.ID = "disable";
disable.Text = "Disable";
disable.AutoPostBack = true;
disable.GroupName = "enableDisableGroup";
disable.CheckedChanged += new EventHandler(disableRadioButton_CheckedChanged);

UpdatePanel upEnableDisable = new UpdatePanel();
upEnableDisable.UpdateMode = UpdatePanelUpdateMode.Conditional;
upEnableDisable.ContentTemplateContainer.Controls.Add(enable);
upEnableDisable.ContentTemplateContainer.Controls.Add(disable);

AsyncPostBackTrigger enableTrigger = new AsyncPostBackTrigger();
enableTrigger.ControlID = enable.ID;
enableTrigger.EventName = "CheckedChanged";
upEnableDisable.Triggers.Add(enableTrigger);
AsyncPostBackTrigger disableTrigger = new AsyncPostBackTrigger();
disableTrigger.ControlID = disable.ID;
disableTrigger.EventName = "CheckedChanged";
upEnableDisable.Triggers.Add(disableTrigger);

mainDiv.Controls.Add(upEnableDisable);
于 2012-05-05T14:20:25.907 に答える