This problem can be solved by creating a custom event in UC2 and using this event on the main page to call the hide method in UC1.
You declare a delegate in your user control
public delegate void HideTextBoxEventHandler(object sender, EventArgs e);
Then define an event for the delegate you created.
public event HideTextBoxEventHandler HideTextBox;
At the code point where you want to hide the text box, you need to trigger this event:
if (this.HideTextBox != null) // if there is no event handler then it will be null and invoking it will throw an error. { EventArgs e = new EventArgs(); this.HideTextBox(this, e); }
Then from the main page create an event handling method
protected void UserControl2_HideTextBox(Object sender, EventArgs e) { UC1.InvokeHideTextBox();
You will need to add to the page load or ever load UC2
UC2.HideTextBox += new UserControl2.HideTextBoxEventHandler(this.UserControl2_HideTextBox);
source share