how to add css class to html generic control div?

前端 未结 9 2216
名媛妹妹
名媛妹妹 2020-12-13 08:21

I created a div tag like this:

System.Web.UI.HtmlControls.HtmlGenericControl dynDiv = 
    new System.Web.UI.HtmlControls.HtmlGenericControl(\"DIV\");
         


        
9条回答
  •  渐次进展
    2020-12-13 08:40

    If you're going to be repeating this, might as well have an extension method:

    // appends a string class to the html controls class attribute
    public static void AddClass(this HtmlControl control, string newClass)
    {
        if (control.Attributes["class"].IsNotNullAndNotEmpty())
        {
            control.Attributes["class"] += " " + newClass;
        }
        else
        {
            control.Attributes["class"] = newClass;
        }
    }
    

提交回复
热议问题