Hi Fred,
This is not proper way of solving the problem. It may not work because if
the control is nested within a container control, you have to call
FindControl recursively or use "$" separator when passing the control id to
FindControl method. There's another, much more effective and cleaner way of
doing this type of task, by exposing a property from the user control, which
then can be set or read by the containing page. Let's imagine your user
control has got a text box for extering a user's first name. Containing page
does not know the internal structure of the user control (well it shouldn't
know), therefore it's better to create a property to abstract the First Name:
-- user control --
public string FirstName
{
get
{
return txtFirstName.Text;
}
set
{
txtFirstName.Text = value;
}
}
now, on the containing page set / get the value of the property,
1. declaratively in the aspx code
<uc1:MyCustomControl runat="server" id="myControl" FirstName="Fred"/>
2. or programatically in the code behind:
protected void btn_Click(object sender, EventArgs e)
{
SaveUserDataToDataBase(myControl.FirstName);
}
Hope this helps