Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a webpart page which have 2 custom visual webparts. When i set the debugger point on both the page loads of the webpart the 2nd visual webpart debugger is hit...that makes me think the 2nd webpart is loading first ..how can i make the first webpart to load first?

FYI - both the webparts call same funtions but outputs are different

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Source: Control Web Part Load Order

If so you can set these properties in the Property Bag, have a look at SPWeb.Properties.

You can modify either in a web browser or via code using the SPLimitedWebPartManager.

Use the MoveWebPart method to reorder.

Hope this helps

share|improve this answer
1  
As far as I know, the webparts will execute in the order they appear on the page. Delete them and re order them should also solve the issue. –  Fox Dec 19 '12 at 8:19

I dont realy get your question, to understand you correct. You have a visual webpart that you made and are calling two ascx from within it?

or

you have a webpart that contains two vistaul webparts?

code is Procedural in c#.

either way, you need to call the first one in the call stack.... meaning your code as anyother code goes from the top first and makes its way down the code stack, having your first call should be the first webpart or ascx and then the second webpart or ascx.

just as an example in my create child controls i want to call two ascx i would do the following:

    protected override void CreateChildControls()
    {
       //called first
       UserControl control = (UserControl)Page.LoadControl(@"/_controltemplates/callMeFirst.ascx");

       //called second
       UserControl control2 = (UserControl)Page.LoadControl(@"/_controltemplates/callMeSecond.ascx");

   }

so above shows that the first line of code is executed first and then the second. Displaying is different because you can just add it in any order like so:

    protected override void CreateChildControls()
    {
       //called first
       UserControl control = (UserControl)Page.LoadControl(@"/_controltemplates/callMeFirst.ascx");

       //called second
       UserControl control2 = (UserControl)Page.LoadControl(@"/_controltemplates/callMeSecond.ascx");

       //add first
       Controls.Add(control);
       //add second
       Controls.Add(control2);

       or

       //add first
       Controls.Add(control2);
       //add second
       Controls.Add(control);
   }

as you can see above the first controls to be added to the page is control and then control2 , you can mix and match control2 first and then control will show in that order but getting the ascx in control is called first befor control2.

this consept is the same for anything else be it in webpart or not :) so in your code (webpart) you need to look at what visual webpart is being called first, rather than looking in the visual webpart itself :) (debug webpart not visual webpart as it will show you what is calling the visual webpart)

hope it helps :)

share|improve this answer
    
Hi Thanks for the answer, i have two separate visual webparts –  spStacker Dec 19 '12 at 16:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.