Difference between Class vs CSSClass in ASP.Net CSS + CSS syntax question

后端 未结 6 1507
挽巷
挽巷 2020-12-29 23:21

What is the difference between:

and

6条回答
  •  情歌与酒
    2020-12-30 00:21

    Actually, there is a difference between class and CssClass: the class will not be seen by the code behind, but the CssClass will.

    Thus, if you add a new class to a control in your code behind, for example:

    myControl.CssClass += " foo";
    

    while your control is set as follows:

        
    

    (Note class attribute: class="Text")

    When inspecting your rendered element in your browser, you will see that it will be rendered as follows:

    
    

    (Note how the class has been overridden: class= " foo".)

    If you set the CssClass on the other hand:

    
    

    you will get it rendered (as expected) like so:

    
    

    (note the class has now both classes set, as expected! class="Text foo")

提交回复
热议问题