1
I’m doing a project with creating dynamic objects with CSS, after he enters the for, he inserts all the data of the database right, but apparently at the end he makes an infinite loop and appears this message:
An unhandled Exception of type 'System.Stackoverflowexception' occurred in System.Web.dll
int qtd = 0;
clsNoticia noticia = new clsNoticia();
List<string> codigosNoticias = new List<string>();
for (int i = 0; i < codigosNoticias.Count; i++)
{
noticia.carregaNoticia(codigosNoticias[i]);
#region Noticias Criadas Dinamicamente
Label lblTituloNoticia = new Label();
lblTituloNoticia.CssClass = "tituloNoticia";
lblTituloNoticia.ID = "tituloNoticia_" + noticia.cd_noticia;
lblTituloNoticia.Text = noticia.nm_titulo;
Label lblLinhaFina = new Label();
lblLinhaFina.CssClass = "linhaFina";
lblLinhaFina.ID = "linhaFina_" + noticia.cd_noticia;
lblLinhaFina.Text = noticia.nm_linha_fina;
Panel pnlTituloNoticia = new Panel();
pnlTituloNoticia.ID = "pnlTituloNoticia";
pnlTituloNoticia.Controls.Add(lblTituloNoticia);
Panel pnlLinhaFina = new Panel();
pnlLinhaFina.ID = "pnlLinhaFina";
pnlLinhaFina.Controls.Add(lblLinhaFina);
Image img_noticia = new Image();
if (noticia.ic_destaque)
{
img_noticia.CssClass = "col1Img";
}
else
{
if (qtd <= 2)
{
img_noticia.CssClass = "col2Img";
qtd++;
}
else
{
img_noticia.CssClass = "col3Img";
qtd++;
if (qtd == 6)
{
qtd = 0;
}
}
}
if (File.Exists(Request.PhysicalApplicationPath + @"\images\noticias\" + noticia.cd_noticia + ".jpg"))
{
img_noticia.ImageUrl = "~/images/noticias/" + noticia.cd_noticia + ".jpg";
}
HyperLink lnkNoticia = new HyperLink();
lnkNoticia.ID = "link_" + noticia.cd_noticia;
lnkNoticia.CssClass = "linkPadrao";
lnkNoticia.Controls.Add(img_noticia);
lnkNoticia.Controls.Add(pnlTituloNoticia);
lnkNoticia.Controls.Add(pnlLinhaFina);
Panel pnlNoticia = new Panel();
pnlNoticia.ID = "noticia_" + noticia.cd_noticia;
if (noticia.ic_destaque)
{
pnlNoticia.CssClass = "col1";
pnlNoticia.CssClass = "mainContBloco";
}
else
{
if (qtd <= 2)
{
pnlNoticia.CssClass = "col2";
pnlNoticia.CssClass = "col2Bloco";
}
else
{
pnlNoticia.CssClass = "col3";
pnlNoticia.CssClass = "col3Bloco";
if (qtd == 6)
{
qtd = 0;
}
}
}
pnlNoticia.Controls.Add(lnkNoticia);
#endregion
pnlNoticia.Controls.Add(pnlNoticia);
}
}
It was a very syntactic error, in the last line of code I put
pnlNoticia.Controls.Add(pnlNoticia);
but I had created a Panel with the same name in index.html, so I just had to change the name, so it didn’t run, but thanks for the help :D– Elián Roventini