简体   繁体   中英

Programatically creating ASP.NET PlaceHolders in C#

I am trying to create a loop that will write some data and add an ASP.NET placeholder to the bottom of the each looped item that I can reference later through other events. The code runs, but the placeholder isn't being added to the ASP.net page. I verified this by looking at the source in the browser. I am not seeing any of the breaks and the label text isn't displaying. Any thoughts/suggestions would be appreciated.

        for (int T = 0; T <= 26; T++)
        {
            Label x = new Label();
            x.ID = T.ToString();
            x.Text = "orem ipsum dolor sit amet, consectetur adipiscing elit. Nulla blandit id felis ac volutpat. Aenean tempor faucibus est, ac feugiat libero egestas sit amet. Aliquam";

            Response.Write("Control ID = " + T.ToString());
            string temp = "question_" + T.ToString();

            PlaceHolder pcl = new PlaceHolder();
            pcl.ID = "test_" + T.ToString();
            pcl.Controls.Add(x);
            pcl.Controls.Add(new LiteralControl("<br><br>"));
        }

您必须将PlaceHolder添加到页面的控件集合中:

this.Controls.Add(pcl);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM