1

I have a main panel which is called linksAndPicturesPanel within this panel, I want to add more panels -> 1 panel for the link and 1 panel for a picture (red and green). enter image description hereFurthermore, it should be possible to add multiple links and pictures. To add those panels I use this code:

 Panel linkPanel = new Panel();
 linkPanel.CssClass = "linkList";
 linkPanel.Controls.Add(new LiteralControl("blablabla -----"));

 Panel picturePanel = new Panel();
 picturePanel.CssClass = "pictureFromLink";
 picturePanel.Controls.Add(new LiteralControl("blablabla22222 -----"));

 linksAndPicturesPanel.Controls.Add(linkPanel);
 linksAndPicturesPanel.Controls.Add(picturePanel);

This works fine for one line. After adding multiple lines, the page reloads and all lines exept the last one are gone. Is there a way, to prevent a page reload so that there all added items will be displayed ?

  • Have you tried looking at ASP:UpdatePanel? – user2536 Mar 18 '13 at 13:43
0

SharePoint UI is built as a Web Application. Web Application are Stateless and that is the reason why controls you are generating dynamically are lost on postback.

To eliminate this you should handle the Page_Load event and create the controls.

 protected void Page_Load(object sender, EventArgs e)
 {
    Panel linkPanel = new Panel();
    linkPanel.CssClass = "linkList";
    linkPanel.Controls.Add(new LiteralControl("blablabla -----"));

    Panel picturePanel = new Panel();
    picturePanel.CssClass = "pictureFromLink";
    picturePanel.Controls.Add(new LiteralControl("blablabla22222 -----"));

    linksAndPicturesPanel.Controls.Add(linkPanel);
    linksAndPicturesPanel.Controls.Add(picturePanel);
 }

Also you should use Session for saving the data during postback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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