Derive all web user controls from a common base class and expose this function as a public method (or methods). Your base class can be obtained from UserControl (as usual, as usual .ascx), and your controls in turn receive from it.
Then, even if using reflection seems a little work, you do it only once. If the text fields are dynamic and you want to avoid hardcoding errors, this will be the way to go.
So, if you just need to get the value of the text field by id from the parent, you can add something like the following to your base class:
public string GetTextboxValue(string id) { string textValue = string.Empty; Control ctl = FindControl(id); if (ctl.GetType() == typeof(TextBox)) textValue = ((TextBox)ctl).Text; return textValue; }
I would say that you need to go this route compared to the previous proposal to open a TextBox, since you really only want to read the text value from the parent and not subject the entire object to reading / writing.
source share