Link to home
Start Free TrialLog in
Avatar of LloydMc
LloydMc

asked on

Programatically added user control's IsPostback property

Hello all,

We are programatically loading user controls at run time using a place holder control.  The IsPostback property of these programatically loaded user controls are always true in the UC's Page_Load, Page_PreRender and Init events. In this case I need to populate a drop down list on the UC,  but I only want to do this once when it's initially loaded.  Is there a way to detect an initial load for a dynamically added user control?
Avatar of martie_11
martie_11
Flag of United States of America image

Assuming A.aspx loads user control B through a placeholder:

In A.aspx:

protected override bool OnBubbleEvent(object source, EventArgs args)
{
      B B1 = source as B;

      if (B1 != null)
      {
            // do what ever yo want
            return true; // to stop further bubbling of event
      }
      return base.OnBubbleEvent (source, args);
}

In B.aspx.cs - the user control:

private void Page_Load(object sender, System.EventArgs e)
{
      if (!IsPostBack)
      {
            RaiseBubbleEvent(this, e);
      }
}

...That just might do it : )
In B.aspx.cs - the user control

should be

In B.ascx.cs - the user control

...Although now that I re-read the Q, I'm not entirely convinced I anwered it... : p
ASKER CERTIFIED SOLUTION
Avatar of NowaY
NowaY

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial