Here's the best I could find to do this dynamically. You can create a javascript function to change the css class which accepts the clientID of the control to change and a string for the css class as parameters. You can set this to be called in the onload() method of the body dynamically passing in the clientID and the css class. This enables you to change the css class for different states of the page.
HtmlGenericControl body = (HtmlGenericControl)uPanel.Page.Master.FindControl("masterBody");
body.Attributes.Add("onload", "setCSSClass('" + uPanel.ClientID.ToString() + "', '" + cssClassName + "')");