Click here to Skip to main content
15,917,731 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

Any simple solution to bellow situation?

I have a custom user control. That controls contains several TextBox controls inside.
In page I generate these controls so I might have between 1 and 30 of these custom user controls. These controls are generated from C# code (code behind file).

When user presses a button I need to get these controls individually so I could get the values from these textboxes. I am exposing these textbox values though properties, so the only problem here is how to get to the parent (individual custom control).

Updated 3-Nov-14 4:35am
Maciej Los 3-Nov-14 12:18pm    
What have you tried?
MK-Gii 3-Nov-14 12:46pm    
FindControl was the only thing I've tried as I don't really know other ways out. But that did not quiet work due to control hierarchy.
Maciej Los 3-Nov-14 12:52pm    
Does div1 and div2 have their names?
MK-Gii 3-Nov-14 13:10pm    
Yes - they both do have. And can have IDs in case there is a need.

Try using FindControl[^] - the link includes an example.
Share this answer
MK-Gii 3-Nov-14 11:47am    
That might be hard. My controls are put into table cells for ordering. In the page I have 2 <div> elements (both are server side controls with runas="server"). In 1st div I put the table with all the custom controls and in another I place a button. With button press I need somehow navigate though the hierarchy all the way up and then down into table... that would be a bit nasty... so was wondering if there is an easier solution.
For the moment I am only thinking about recursive function that would loop everything looking for my type controls in the whole page... but it's just an idea...
Here is an idea how to find child control in ASP.NET:[^]

I'd suggest to create user control. For further information, please see:
User controls in ASP .NET[^]
ASP.NET User Controls[^]
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