how to add a div to container div in c# code behind

前端 未结 5 1570
慢半拍i
慢半拍i 2020-12-17 09:18

ASP.NET, C#

As the title suggests I was wondering if anyone knew how to programatically (c# code behind file) add a div to another a container div (in the aspx page)

5条回答
  •  粉色の甜心
    2020-12-17 09:39

    Aside from using a Panel like ocdecio suggested, there are several other possibilities.

    • You can use an asp:Literal control inside the div and fill that with pregenerated HTML
    • Add a runat="server" to the div itself and access it as a HtmlGenericControl, adding other controls to it from your codebehind.
    • Using <%= ... %>

    It depends a little on the level of control you need. Still, under a most circumstances, a Panel that starts out invisible would be best:

    Then change the visibility from your codebehind when needed.

    One cases where you might want to use one of the other methods is when you're stuck with some CSS file that assigns styles based on ID. In that case, using .NET controls is not really an option. But really, you should smack your designer over the head and tell him to use class names instead.

提交回复
热议问题