Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering a server-side control using HTMLTextWriter makes control lose standard functionality (i.e. Click eventhandler)
    primarykey
    data
    text
    <p>I want to add Server-Side controls (<code>CheckBoxList</code>s &amp; <code>Button</code>): </p> <p><code>ChkBoxLst1</code> &amp; <code>ChkBoxLst2</code> &amp; <code>Button1</code> through Code-behind and then use an <code>HTMLTextWriter</code> to render the control. </p> <p>I can't seem to be able to do this. </p> <p>All of the above in a Visual WebPart. </p> <p>What I have tried: <br /> Global: <br /></p> <pre><code>CheckBoxList ChkBoxLst2 = new CheckBoxList(); Button Bttn2 = new Button(); Label lbl2 = new Label(); StringWriter stringWriter = new StringWriter(); </code></pre> <p>Page Load:<br /></p> <pre><code>using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter)) { ChkBoxLst2.Items.Add(new ListItem("Three", "3")); ChkBoxLst2.Items.Add(new ListItem("Four", "4")); ChkBoxLst2.RenderControl(writer); lbl2.RenderControl(writer); Bttn2.Click += new EventHandler(this.Bttn2_Click); Bttn2.Text = "Click this HTMLText WriteButton!"; Bttn2.RenderControl(writer); } spn.InnerHtml = stringWriter.ToString(); </code></pre> <p>Event Handler: <br/></p> <pre><code> void Bttn2_Click(Object sender, EventArgs e) { foreach (ListItem item in ChkBoxLst2.Items) { if (item.Selected == true) { if (IsPostBack) { lbl.Text += item.Text + ", "; } } } } </code></pre> <p>The EventHandler does not get triggered and the selected values do not get saved the way I have done it above. Any ideas as to why not? I've tried a comparison of two checkbox lists, but the <code>HTMLTextWriter</code> implementation did not work whereas the simple .NET did of the same thing <br/> all in all I think its my implementation of an HTMLTextWriter/how I add the server control.<br> <br /> Note that the spn is a literal span control in the markup. </p>
    singulars
    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.
 

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