Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox checked state change when visibility is set to false
    primarykey
    data
    text
    <p>I am having some trouble understanding the impact of setting checkbox visibility on the checked state at various stages in the page life cycle.</p> <p>Given below is a sample code for a dynamically created checkbox.</p> <pre><code> protected override void OnInit(EventArgs e) { base.OnInit(e); check = new CheckBox(); check.AutoPostBack = true; check.Text = "checkbox1"; check.ToolTip = "tooltip for checkbox1"; check.CheckedChanged += new EventHandler(check_CheckedChanged); this.Form.Controls.Add(check); Button btn = new Button(); btn.Text = "click me"; btn.Click += new EventHandler(btn_Click); this.Form.Controls.Add(btn); } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { check.Checked = true; check.Text = "text reassigned."; check.ToolTip = "tooltip reassigned"; } } protected override void OnPreRenderComplete(EventArgs e) { base.OnPreRenderComplete(e); check.Visible = false; } </code></pre> <p>The issue here is, when a postback occurs (I click on the button), then I notice in the Page_load event, the checkbox maintains the viewstate of the tooltip and text. However the checked state is changed to false and it fires a CheckedChanged event. Why is the behavior so? </p> <p>Also, if I set the visibility of the checkbox in either PageLoad() or the OnPreRender() event, the checked state of the checkbox is maintained across postbacks and does not fire a CheckedChanged event. </p> <p>I'm just curious as to what happens differently when the visibility is changed in the OnPreRenderComplete event so as to have the checkbox default to an unchecked state.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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