Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you dynamically add a ToggleButtonExtender to a CheckBox control in C#?
    primarykey
    data
    text
    <p>Hoping someone can help me out here.</p> <p>I'm creating a table in some code-behind and trying to dynamically add a <code>ToggleButtonExtender</code> to a standard <code>CheckBox</code>. here is my code:</p> <pre><code>cell = new TableCell(); CheckBox cb = new CheckBox(); cb.ID = "myID"; cb.Checked = true; cell.Controls.Add(cb); // ToggleButton control to allow user to toggle images. ToggleButtonExtender toggleButton = new ToggleButtonExtender(); toggleButton.ID = "Toggle" + cb.ID; toggleButton.TargetControlID = cb.ID; toggleButton.ImageWidth = 32; toggleButton.ImageHeight = 32; toggleButton.CheckedImageAlternateText = "Check"; toggleButton.UncheckedImageAlternateText = "UnCheck"; toggleButton.UncheckedImageUrl = @"~/imgs/x.png"; toggleButton.CheckedImageUrl = @"~/imgs/check.png"; toggleButton.Enabled = true; cell.Controls.Add(toggleButton); row.Controls.Add(cell); </code></pre> <p>I get this error when it tries to create the table:</p> <p><code>Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element</code></p> <p>If I remove the <code>ToggleButtonExtender</code> creation logic the table is created just fine (but without the <code>ToggleButtonExtender</code> functionality I want).</p> <p>Any ideas? I've tried various things over the past few hours but nothing works.</p> <p>Thanks!</p> <p>----- UPDATE------</p> <p>This works:</p> <pre><code>&lt;asp:Panel ID="myPanel" runat="server"&gt; &lt;/asp:Panel&gt; CheckBox cb = new CheckBox(); cb.ID = "myCB"; cb.Checked = true; myPanel.Controls.Add(cb); ToggleButtonExtender toggleButton = new ToggleButtonExtender(); toggleButton.ID = "ToggleButtonExtender" + cb.ID; toggleButton.TargetControlID = cb.ID; toggleButton.ImageWidth = 50; toggleButton.ImageHeight = 50; toggleButton.UncheckedImageUrl = @"~/imgs/x.png"; toggleButton.CheckedImageUrl = @"~/imgs/check.png"; myPanel.Controls.Add(toggleButton); </code></pre> <p>But adding it to a <code>TableCell</code> doesn't seem to be working.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload