0

I'm developing a website where I need to sort some static asp:UpdatePanels and asp:Panels including all controls inside these panels in according to database setup But I don't know how to do it :-( Is there anyone who can help me?

I have tried to setup all the panels including both Panels and UpdatePanels in an aspx file and in code behind reordered them with the following code with no success :-(

this is my aspx:

<asp:Panel runat="server" ID="panelMain">
    <asp:UpdatePanel runat="server" ID="2"></asp:UpdatePanel>
    <asp:Panel runat="server" ID="1"></asp:Panel>
    <asp:UpdatePanel runat="server" ID="3"></asp:UpdatePanel>
</asp:Panel>

this is my c# code:

Control control2 = panelMain.FindControl("2");
Control control1 = panelMain.FindControl("1");
Control control3 = panelMain.FindControl("3");

panelMain.Controls.Clear();

panelMain.Controls.Add(control1);
panelMain.Controls.Add(control2);
panelMain.Controls.Add(control3);

The UpdatePanel must be registered in ScriptManager - and I can't sort the components - so I don't know what to do and how to register them :-(

0

1 Answer 1

0

According to Mike Perrenoud's answer on this Question you can make all variants of the three controls invisible and make only the ones visible which are needed and assign the active panel the values that you want to show like you already do.

The aspx site could look like this:

<asp:Panel runat="server" ID="panelMain">
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" Visible="false">
    </asp:UpdatePanel>
    <asp:Panel runat="server" ID="Panel2" Visible="false">
    </asp:Panel>
    <asp:UpdatePanel runat="server" ID="UpdatePanel2" Visible="false">
    </asp:UpdatePanel>
    <asp:UpdatePanel runat="server" ID="UpdatePanel3" Visible="false">
    </asp:UpdatePanel>
    <asp:UpdatePanel runat="server" ID="UpdatePanel4" Visible="false">
    </asp:UpdatePanel>
    <asp:Panel runat="server" ID="Panel3" Visible="false">
    </asp:Panel>
    <asp:Panel runat="server" ID="Panel4" Visible="false">
    </asp:Panel>
    <asp:UpdatePanel runat="server" ID="UpdatePanel5" Visible="false">
    </asp:UpdatePanel>
    <asp:UpdatePanel runat="server" ID="UpdatePanel6" Visible="false">
    </asp:UpdatePanel>
</asp:Panel>

And on the C# side you can assign values and make it visible:

 UpdatePanel updatePanel1Data = (UpdatePanel)panelMain.FindControl("UpdatePanel1");
 Panel panel1Data = (Panel)panelMain.FindControl("Panel1");
 UpdatePanel updatePanel2Data = (UpdatePanel)panelMain.FindControl("UpdatePanel2");

 UpdatePanel3 = updatePanel1Data;
 Panel2 = panel1Data;
 UpdatePanel4 = updatePanel2Data;

 UpdatePanel1.Visible = false;
 Panel1.Visible = false;
 UpdatePanel2.Visible = false;

 UpdatePanel3.Visible = true;
 Panel2.Visible = true;
 UpdatePanel4.Visible = true;

This way it seems for the user that you reordered the panels. Example is not testet, but it could give you an idea.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering - but what if Panel2 has to be an UpdatePanel2? I think that it still seems to be a kind of static!
@MichaelEriksen you can try something like that, but im not sure if its working. UpdatePanel updatePanel2Data = (UpdatePanel)panelMain.FindControl("Panel2");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.