Solved

Dynamic checkbox control in SharePoint 2007 web part

Posted on 2008-06-23
5
1,683 Views
Last Modified: 2010-05-18
I have created dynamic check boxes in SharePoint 2007 web part but I am not able to read the values of checkboxes which are checked. Please
private void IterateControls(Control Parent)

        {

            

          foreach (Control child in Parent.Controls)

            {

                

                if (child.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))

                {
 

                    CheckBox chkBool = (CheckBox)child;
 

                    if (chkBool.Checked == true)

                    {

                        int i = 0;

                        strLenderName.Add(chkBool.ID.ToString());

                        i++;

                    }

                }
 

                if (child.Controls.Count > 0)

                {

                    IterateControls(child);

                }

            }

           

           

            for (int j = 0; j < strLenderName.Count; j++)

            {

                Page.Response.Write("strLenderName" + strLenderName[j].ToString());

            }

        }
 
 

        private void btnSubmit_Click(Object Sender, EventArgs e)

        {

            try

            {

                

                IterateControls(this);

                

            }

            catch (Exception eXSubmt)

            {

                Page.Response.Write("Error Message" + eXSubmt.Message);

            }

        }

Open in new window

0
Comment
Question by:lakshmidurga
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
argodev earned 500 total points
ID: 21851934
You indicated that you created the controls dynamically... when? during CreateChildControls or ?

Are you re-creating them on Page Init? Due to the flow of the asp.net page lifecycle, you have to re-create any dynamically created controls in Page_Init so that they exist prior to view-state being applied. If not, they are not there when the system applies viewstate and therefore the values are lost.

The following is an old, but helpful article on the topic.
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx 
0
 
LVL 7

Author Comment

by:lakshmidurga
ID: 22004441
close this question.Thanks for Helping
0
 
LVL 3

Expert Comment

by:argodev
ID: 22015498
The answer provided would appear to have given the asker the solution needed. No counter question was asked nor was any clarification requested. In my opinion, points should be awarded for a correct answer rather than being refunded to the asker.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Closing all open child forms. 4 38
Vb.Net Date Formatting Assistance 4 36
Help with LINQ and XML 10 27
Close form "before" open 3 28
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now