By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,354 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,354 IT Pros & Developers. It's quick & easy.

Dynamic Checkboxe Problem in ASP .NET

P: n/a
Hi All,

I created a dynamic checkbox in ASP .Net inside a Button1_Click event method
(outside the page_load event) and performed the event handling method for the
CheckedChanged event and I check the checkbox at runtime nothing happens
(checkBoxObj.check is always false). Does anyone have information on how to
make this work? Note: I can get it to work inside Page_Load event. I need
help in getting it to work in different event method. See my below code
snippet:
protected void Button1_Click(object sender, EventArgs e)
{

// Create new CheckBox control.
CheckBox NewCheckBox = new CheckBox();
NewCheckBox.ID = "CheckBoxId";
NewCheckBox.Text = "Dynamic CheckBox";
NewCheckBox.AutoPostBack = true;
//// Register the event-handling method for the CheckedChanged event.
NewCheckBox.CheckedChanged += new EventHandler(this.Check_Change);

// Add the control to the Controls collection of the
// PlaceHolder control.
Place.Controls.Clear();
Place.Controls.Add(NewCheckBox);

}

void Check_Change(Object sender, EventArgs e)
{

// Retrieve the CheckBox control from the PlaceHolder control.
CheckBox check = (CheckBox)Place.FindControl("CheckBoxId");

// Display the appropriate message based on the state of the
// CheckBox control.
if (check.Checked)
{
TextBox1.Text = "I'm checked";
}
else
{
TextBox1.Text = "I'm not checked";
}

}


Thanks!

Sep 1 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.