• <legend id='zbm7X'><style id='zbm7X'><dir id='zbm7X'><q id='zbm7X'></q></dir></style></legend>

      <small id='zbm7X'></small><noframes id='zbm7X'>

    1. <i id='zbm7X'><tr id='zbm7X'><dt id='zbm7X'><q id='zbm7X'><span id='zbm7X'><b id='zbm7X'><form id='zbm7X'><ins id='zbm7X'></ins><ul id='zbm7X'></ul><sub id='zbm7X'></sub></form><legend id='zbm7X'></legend><bdo id='zbm7X'><pre id='zbm7X'><center id='zbm7X'></center></pre></bdo></b><th id='zbm7X'></th></span></q></dt></tr></i><div id='zbm7X'><tfoot id='zbm7X'></tfoot><dl id='zbm7X'><fieldset id='zbm7X'></fieldset></dl></div>

        <bdo id='zbm7X'></bdo><ul id='zbm7X'></ul>
        <tfoot id='zbm7X'></tfoot>

        动态(以编程方式)添加复选框和checkedchanged事件

        时间:2023-09-16
        <legend id='4QtWK'><style id='4QtWK'><dir id='4QtWK'><q id='4QtWK'></q></dir></style></legend>

        • <bdo id='4QtWK'></bdo><ul id='4QtWK'></ul>
          <tfoot id='4QtWK'></tfoot>

              <tbody id='4QtWK'></tbody>
              <i id='4QtWK'><tr id='4QtWK'><dt id='4QtWK'><q id='4QtWK'><span id='4QtWK'><b id='4QtWK'><form id='4QtWK'><ins id='4QtWK'></ins><ul id='4QtWK'></ul><sub id='4QtWK'></sub></form><legend id='4QtWK'></legend><bdo id='4QtWK'><pre id='4QtWK'><center id='4QtWK'></center></pre></bdo></b><th id='4QtWK'></th></span></q></dt></tr></i><div id='4QtWK'><tfoot id='4QtWK'></tfoot><dl id='4QtWK'><fieldset id='4QtWK'></fieldset></dl></div>
                • <small id='4QtWK'></small><noframes id='4QtWK'>

                  本文介绍了动态(以编程方式)添加复选框和checkedchanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在以编程方式添加几个复选框和事件处理程序时遇到了一点问题.复选框看起来都很好,但单击时它们不做任何事情.有谁知道我做错了什么?

                  I am having a bit of a problem adding a few check boxes and an event handler programatically. The check boxes all appear fine, but they don't do anything when clicked. Does anyone have any idea what I am doing wrong?

                  foreach (Statement i in theseStatements)
                  {
                      box = new CheckBox();
                      box.Text = i.StatementText;
                      box.AutoPostBack = true;
                      box.CheckedChanged += new EventHandler(this.CheckedChange);
                      PlaceHolder.Controls.Add(box);
                  }
                  
                  protected void CheckedChange(object sender, EventArgs e) 
                  {
                      CheckBox x = (CheckBox)sender;
                      Instructions.Text = "change";            
                      WorkPlaceHazardsBox.Text += x.Text;
                  } 
                  

                  推荐答案

                  你应该做到以下几点:

                  1. 为您在 foreach 循环中创建的每个 CheckBox 实例设置 ID 属性.
                  2. 对于 PostBacks,请确保已创建 CheckBox,并在页面生命周期的某个时间点附加 CheckedChanged 事件处理程序在引发控件事件之前
                  1. Set the ID property for each instance of CheckBox you create in your foreach loop.
                  2. For PostBacks, ensure that your CheckBoxes are created and CheckedChanged event handler is attached at some point of the page life-cycle before control events are raised

                  这篇关于动态(以编程方式)添加复选框和checkedchanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将所有标准事件处理程序替换为 WeakEventManager 或其变体是否安全? 下一篇:在 .NET 中查找 Windows 窗体控件的所有事件处理程序

                  相关文章

                    <tfoot id='fiiQx'></tfoot>

                  1. <i id='fiiQx'><tr id='fiiQx'><dt id='fiiQx'><q id='fiiQx'><span id='fiiQx'><b id='fiiQx'><form id='fiiQx'><ins id='fiiQx'></ins><ul id='fiiQx'></ul><sub id='fiiQx'></sub></form><legend id='fiiQx'></legend><bdo id='fiiQx'><pre id='fiiQx'><center id='fiiQx'></center></pre></bdo></b><th id='fiiQx'></th></span></q></dt></tr></i><div id='fiiQx'><tfoot id='fiiQx'></tfoot><dl id='fiiQx'><fieldset id='fiiQx'></fieldset></dl></div>

                    1. <small id='fiiQx'></small><noframes id='fiiQx'>

                      <legend id='fiiQx'><style id='fiiQx'><dir id='fiiQx'><q id='fiiQx'></q></dir></style></legend>
                        <bdo id='fiiQx'></bdo><ul id='fiiQx'></ul>