Dynamic check box checked status

laxman

Freshman
Joined
Jun 14, 2008
Messages
28
hai,

i am generating check boxes dynamically (code is given below) i wanted to capture the check box checked status plz help me how to do this, dont consider that i have given both text property and ID are same as this i am testing i have given this

CheckBox chk;
chk = new CheckBox;
DateTime dt = DateAndTime.DateAdd(DateInterval.Day, 1, date1);
String str = dt.ToString("D");
String[] abc = str.Split(new Char[] { ',' });
Panel1.Controls.Add(chk);
chk.ID=abc[0];
chk.Text=abc[0];
chk.Width=150;
chk.Height=50;

If Possible give me sample example
 
You should be able to do a FindControl on the page based on the assigned ID - simply cast the result back to a CheckBox and you should be ablse to get it's value.
 
If you are dealing with dynamically created controls you need to be aware of the life cycle of the page to make sure the state gets persisted.

Do an image search for "ASP.Net page lifecycle", a must have resource for asp.net programmer.

You'll see the state is persisted between OnInit and Load. Therefore, for you checkbox to have the state set automgically you'll need to create it in OnInit and then you can access the value after the Load event. I suspect that's your problem but you haven't shown when or how you are getting the value.


Alternatively you can get it yourself from the request if you know the client ID of the control.
Code:
string value = Context.Request.Form["clientId"];
 
Back
Top