laxman Posted December 26, 2008 Posted December 26, 2008 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 Quote
Administrators PlausiblyDamp Posted December 26, 2008 Administrators Posted December 26, 2008 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JohnsHandle Posted January 8, 2009 Posted January 8, 2009 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. string value = Context.Request.Form["clientId"]; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.