Click here to Skip to main content
15,916,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am placing a user control at run time (n nos. of time, which depends on user input) and can read their name and values by following code:

IDictionary<string,> TextValues = new Dictionary <string,>();
            foreach (Control c in this.Controls)
            {
                if (c.HasChildren)
                {
                    foreach (Control TB in c.Controls)
                    {
                        if (c.HasChildren)
                        {
                            foreach (Control pB in TB.Controls)
                            {
                                if (pB is TextBox)
                                {
                                    TextValues.Add(pB.Name, pB.Text);
                                }
                            }
                        }
                    }
                }

For Example, We have a usercontrol named x and we are showing x on a form nos. of y times. Suppose user enter y=5. It means that I have 5 records on single form which will be stored in database with single click.

Problem area is that each x's control has same Id.

How sort out it?

Regards!
Aman
Posted
Updated 15-Feb-11 1:47am
v4
Comments
ketand1 15-Feb-11 5:06am    
Hi
You have to create a properties in the user control to access the child controls of the user control
or make all the access specifiers as public to access them out side the user control
For Example return value of text box you should create property like
public String Text
{
get{return textbox1.Text;}
set{textbox1.Text = value;}
}
I thing this is the solution please find whether it is correct or not.


Thanks

This[^] may help.
 
Share this answer
 
Hope this[^] might give you an idea.
 
Share this answer
 
by other foriegn primary key in place of primary id
 
Share this answer
 
once u r creating controls at runtime, then u can set certain properites, like text, tag, name etc

keep record of these properties and later onwhile reading u can identify with which control u r dealinh at the moment

for example u can keep a variable i, which keep on incrementing each time a control is created, and then u assign the name property of the conrol to

con.Name= "some_name"+i.ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900