views:

24

answers:

2

Hi to all,

I have a MasterPage that has two image buttons , and two content pages, What i want is that when an Image button is clicked ----> the theme changes.

I know that MasterPage do not have a "OnPreInit" function and the theme has to be changed inside the "OnPreInit" function...

so is there any workaround for this problem ???

Thanks in advance.

Baher

+1  A: 

The following is a process used in the Book "Beginning ASP.Net 4 in C# and VB.Net by Imar Spaanjaars". Note that in the book he uses a DropDownList to change the Theme, but I believe the same can be done with an Image button:

  1. In the MasterPage add code to the Image Button click event to save the theme name into a cookie. Once the cookie is set you redirect back to the current page.
  2. You will need to create a custom BasePage that inherits from the Page class and have all your pages inherit from this BasePage. It is in this BasePage that you will override the Page_PreInit to load the selected theme based on the value of the cookie. The redirect is to run the code in the Page_PreInit to have the Theme change.

I know this might not be the best option, because you will need to change all your pages to inherit from your new BasePage instead of Page.

Waleed Al-Balooshi
I'm sorry, I'm just trying to change the theme from a MasterPage, and all my pages already inherit from it.I need to do something related to my MasterPage.thanks.
Baharanji
You can't change the theme from the MasterPage. It must be done from the content page. The solution Waleed describes will automate this job, introducing a special page controller. This problem is discussed on ASP.NET too: http://forums.asp.net/p/771655/771789.aspx.
Dirk
A: 

Well I found the Solution for that which is i captured the Image Button clicked and then changed the theme

really easy

Baharanji