locked
multiple webparts are loaded RRS feed

  • Question

  • User431416295 posted

    Hello.


    I've just started to look into Web Parts and created a simple page that loads a Web User Control into a zone.

    When I run tha page it loads fine, but when I set some breakpoint and try to debug it looks like it runs the Page_load on a previous control that I tested with 5-6 times (or more) and then the control that I try to add is triggers 3 times before the CreateChildControl function is called on the page that should load the controls.

    This is the code I use to add the Web Parts, but before this code is triggers the Page_Load on the MetTextAccordion and another control is triggered multiple times.


    protected override void CreateChildControls()
    {
    base.CreateChildControls();

    if (!Page.IsPostBack)
    {
    // create Web Part instance from User Control file
    Control uc = this.LoadControl(@"Components\MetTextAccordion.ascx");
    uc.ID = "wp2";

    GenericWebPart wp2 = WebPartManager1.CreateWebPart(uc);

    wp2.Title = "met text";
    wp2.AllowMinimize = true;
    WebPartManager1.AddWebPart(wp2, WebPartZone1, 1);
    }
    }


    The Page_Lode on this page is empty, and no controls are added thru the GUI anymore.

    Any suggestions on what could happen here?


    Thanks

    Endre

    Thursday, January 7, 2010 7:34 AM

Answers

  • User431416295 posted

    OK, my bad again... Well read up on this Web Part stuff before posting any more questiuons.

    I removed the CreateChildControl code and the modules allready registered was loaded and show if minimized.

    Have to figure out another way to load modules on startup for anonymous users.

    Endre

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 7, 2010 9:26 AM

All replies

  • User431416295 posted

    OK, I figured this one out.

    When using Web Parts, Visual Studio adds an authenitcation database, and stores your personalization.

    When I coded this and tried different ways to add modules and to minimize my modules they all got stored in this database.

    I have now changed to Forms-authentication and cookies, so now it works with just the one Web Part loading.


    Next problem: Web Parts modules disapares when i minimize them... any suggestions? (should start a new thread on this one I guess).


    Endre


    Thursday, January 7, 2010 9:09 AM
  • User431416295 posted

    OK, my bad again... Well read up on this Web Part stuff before posting any more questiuons.

    I removed the CreateChildControl code and the modules allready registered was loaded and show if minimized.

    Have to figure out another way to load modules on startup for anonymous users.

    Endre

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 7, 2010 9:26 AM