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?
LloydMcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

martie_11Commented:
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 : )
martie_11Commented:
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
NowaYCommented:
I think the best way to solve your problem is to cache the values of your dropdownlist.

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Check if DropDownList cache is empty
If  HttpContext.Current.Cache("DropDownList") Is Nothing then
           'if empty then populate the cache with the datasource for the DDL. Could be arraylist, dataset, etc.
            HttpContext.Current.Cache.Insert("DropDownList") = Get_DDL_Datasource()
end If
            'now just populate the DDL with the cached datasource object
            ddl.datasource = HttpContext.Current.Cache("DropDownList")
            ddl.databind()

    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.