PC Review


Reply
Thread Tools Rate Thread

Dynamic Checkboxe Problem in ASP .NET

 
 
Iderocks
Guest
Posts: n/a
 
      1st Sep 2008
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!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox on main form to be set to True based on subform checkboxe =?Utf-8?B?S2VsbGll?= Microsoft Access Form Coding 0 8th Aug 2005 06:35 AM
Maintain Word format in Outlk w protected form & active checkboxe =?Utf-8?B?S2V6ZWUgSw==?= Microsoft Outlook Discussion 2 2nd May 2005 01:19 PM
30 checkboxe possibilities narrow now Carin Bunney Microsoft Access Queries 1 2nd Feb 2005 10:58 PM
Breakpoint checkboxe =?Utf-8?B?Sm9obiBTbWl0aA==?= Microsoft VC .NET 1 18th Feb 2004 05:01 PM
Re: Dynamic DNS Problem Jonathan de Boyne Pollard Microsoft Windows 2000 DNS 1 4th Sep 2003 05:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 PM.