Created
August 6, 2013 14:06
-
-
Save JayDouglass/6164765 to your computer and use it in GitHub Desktop.
Add / Remove CSS class for webforms controls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Module WebControlExtensions | |
<Extension> | |
Public Function AddClass(control As WebControl, cssClass As String) As WebControl | |
Dim cssClasses = control.CssClass.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries).ToList() | |
If Not cssClasses.Contains(cssClass) Then cssClasses.Add(cssClass) | |
control.CssClass = String.Join(" ", cssClasses.ToArray()) | |
Return control | |
End Function | |
<Extension> | |
Public Function RemoveClass(control As WebControl, cssClass As String) As WebControl | |
Dim cssClasses = control.CssClass.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries).ToList() | |
cssClasses.RemoveAll(Function(s) s = cssClass) | |
control.CssClass = String.Join(" ", cssClasses.ToArray()) | |
Return control | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment