Adding Html from Code Behind in Asp.net

前端 未结 5 838
面向向阳花
面向向阳花 2020-12-17 09:38

I want to add HTML structure and control like this from code behind into a panel

First Name
5条回答
  •  情书的邮戳
    2020-12-17 09:57

    Don't add that child control to the panel, add it to the control that should be the parent:

    HtmlGenericControl divcontrol = new HtmlGenericControl();
    divcontrol.Attributes["class"] = "sxro sx1co";
    divcontrol.TagName = "div";
    pnlUserSearch.Controls.Add(divcontrol);
    
    Label question = new Label();
    questionDescription.Text = "text";
    divcontrol.Controls.Add(question); // add to the new div, not to the panel
    

提交回复
热议问题