Change CSS classes from code

后端 未结 7 907
误落风尘
误落风尘 2020-12-03 06:17

It\'s easy to set CssClass in the code-behind, but this runs the risk of overwriting existing classes.

I need to set certain elements to ReadOnly

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 06:59

    Related... if you just want to toggle a Class based upon a condition...

    bool disable = true;      // this will vary (true/false) based on UI state
    
    string newClass = disable ? "BtnGray" : "BtnPink";
    
    string currentClass = disable ? "BtnPink" : "BtnGray";
    
    myButton.CssClass = myButton.CssClass.Replace( currentClass, newClass );
    

提交回复
热议问题