Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are dynamically adding controls at run time you have to make sure that those controls are populated to the page's Control collection before ViewState is loaded. This is so that the state of each checkbox can be rehydrated from Viewstate. The Page Load event, for example, is too late.</p> <p>Typically you would dynamically add your CheckBox controls during the Init Event (before view state is loaded) and then Read the values in your Checkbox controls during the Load event (after view state is loaded).</p> <p>eg:</p> <pre><code>protected override void OnInit(EventArgs e) { //load the controls before ViewState is loaded base.OnInit(e); for (int i = 0; i &lt; 3; i++) { CheckBox cb = new CheckBox(); cb = new CheckBox(); cb.ID = "KeyWord" + i.ToString(); cb.Text = "Key Word" MyPlaceHolder.Controls.Add(new CheckBox()); } } //this could also be a button click event perhaps? protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (Page.IsPostBack) { //read the checkbox values foreach(CheckBox control in MyPlaceHolder.Controls) { bool isChecked = control.Checked; string keyword = control.Text; //do something with these two values } } } </code></pre> <p>Hope that helps</p> <p>****EDIT**** Forgot to mention that this is obviously just demo code - you would need to flesh it out.</p> <p>For more information on dynaic control rendering in ASP.Net check out <a href="http://aspnet.4guysfromrolla.com/articles/092904-1.aspx" rel="nofollow noreferrer">this article on 4Guys</a>.</p> <p>For more information on the page life-cycle in ASP.Net check out <a href="http://msdn.microsoft.com/en-us/library/ms178472(VS.100).aspx" rel="nofollow noreferrer">MSDN</a>.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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