0
votes

I have a user control for showing message of actions. It is hidden on page load of user control, so that it disappears once a warning is acted upon. But in certain cases when a page loads, i want the user control to be visible, but doesn't due to hiding in page load of user control. How can I manage this?

usercontrol

protected void Page_Load(object sender, EventArgs e)
{
    this.Visible = false;
}
public void SetMessage(string title, string desc)
{
    this.Visible = true;
    Title = title;
    Description = desc;
}

parent page

protected void Page_Load(object sender, System.EventArgs e)
{ 
    msgDialogue.SetMessage(a);
}
1

1 Answers

0
votes

From what I understood, you need to show or hide a usercontrol depending on a property value in your page (or in a session variable). If this is the case, you would better add a placeholder in your page, then load the control (or not load it) depending on your condition.

if(condition)
{    
_usercontrol ctrl = LoadControl("~/usercontrols/_usercontrol.ascx") as _usercontrol;
Placeholder1.Controls.Add(ctrl);
}
//otherwise, do not load the control

Hope it helps.