I have this line in my .aspx
code:
<div id="view" class="g2" runat="server">
</div>
but when I want to find this element in C#(aspx.cs
) and send data for it, C# cant find it this way:
view.Controls.Add(item);
*item is a html element that I made through this code:
for(int i=0; i<foods.Count; i++)
{
HtmlGenericControl item = new HtmlGenericControl("div");
item.Attributes["class"] = "items";
item.Style["border_bottom"] = "3px solid aqua";
HtmlImage img = new HtmlImage();
img.Src = foods[i].picGet();
HtmlGenericControl mask = new HtmlGenericControl("div");
item.Attributes["class"] = "mask";
HtmlGenericControl h2 = new HtmlGenericControl("h2");
item.InnerHtml = foods[i].fnameGet();
HtmlGenericControl price = new HtmlGenericControl("span");
item.Attributes["class"] = "price";
item.InnerHtml = foods[i].priceGet().ToString() + "ریال";
HtmlGenericControl desc = new HtmlGenericControl("p");
item.InnerHtml = foods[i].describeGet();
mask.Controls.Add(h2);
mask.Controls.Add(price);
mask.Controls.Add(desc);
item.Controls.Add(img);
item.Controls.Add(mask);
view.Control.Add(item);
}
- I have written the namespace
System.Web.UI.HtmlControls
- I saw a course that did the same thing and was successful
- the error is that even my visual studio cant find the
view
that i used in the last line of the for loop.