I have themes on my website, and i have image buttons on master page ,onButtonClick theme will change..

But as i click the button which is on master page it gives me error

The 'Theme' property can only be set in or before the 'Page_PreInit' event.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The 'Theme' property can only be set in or before the 'Page_PreInit' event.

Source Error:

Line 55: Page.Theme = "Black"
Line 56: ElseIf imgBtn.ID = "ImgBtnBlue" Then
Line 57: Page.Theme = "Blue"
Line 58: ElseIf imgBtn.ID = "ImgBtnGrey" Then
Line 59: Page.Theme = "Grey"





and master page don't have the Pre_Init event ?



whats the solution so that themes can be changed on clicking the buttons on master page