If statements in aspx files

Since you have two controls on the page it will render them both. The if-check you create, only determines whether it's included in the output. The easiest way to prevent this is to change your code like this:

<div>
    <units:MyUserControl runat="server" SomeSetting="<%= Something %>" />
</div>

EDIT: Answer to edit in the original post:

<div>
    <% if(Something) { %>
        <div id="someUniqueMarkup">
            This markup should not be output if Something==true.

            <asp:placeholder id="phItemInDiv" runat="server" />
        </div>
    <% }
    else { %>
        <asp:placeholder id="phItemOutsideDiv" runat="server" />
    <% } %>
</div>



MyUserControl ctrl = (MyUserControl)LoadControl("/pathtousercontrol.ascx")
if (something){    
    phItemInDiv.Controls.Add(ctrl);
}
else{
    phItemOutsideDiv.Controls.Add(ctrl);
}

This way you will only have the user control emitted (and loaded) if Something is true


The best way, in my opinion, is to declare your user control once in the ASPX.

In the code behind, on PageLoad, apply the logic you see fit:

if(something)
    MyUserControl.SomeSettings = ...

If there is a problem in the chronology, do the above logic in PreLoad since it will fire before Page Load of the page and all of its related user controls.

EDIT:

You can put two different IDs on the user controls with Enabled = false. In Page_load, set Enabled to one of them based on the logic you desire.