I have two WebUser Controls which are dynamically added to the Webform a number of times according to the user input from a previous page. There are some textboxes and drop downs in the WebUser control. I need to get the values from the textboxes of the WebUsercontrol which are added dynamically. How do I do that?
A:
Some psuedocode:
Let the parent container control be ParentContainerControl
For Each ctl` In ParentContainerControl.Controls
If ctl is a TextBox
Use ctr.Text
End If
Next
Daniel A. White
2009-04-11 14:16:32
+1
A:
You should expose the control values as properties in your user control. Then you can loop through the container's Controls collection.
foreach (Control ctl in container.Controls)
{
if (ctl is MyUserControl)
{
MyUserControl uctl = (MyUserControl)ctl;
// do something with uctl properties, e.g.
string myString = uctl.Address1;
}
}
Jamie Ide
2009-04-11 14:24:52
What is Address1 given here?
2009-04-11 15:07:17
It's just an example of a possible textbox value that you could expose as a property.
Jamie Ide
2009-04-11 15:32:22
A:
hi, casting to User control Type as far as i know only works in Web Application Project, so you are left with some other options - create a session or viewstate value and shared it amongst these controls. - create a base class that both these user controls inherit from, and in the base calass you can define your properties that the controls should interact through. -create an Interface , where both these user controls will implement.
hope this helps.