Thursday, April 28, 2011

Theme Swap

Problem/Challenge:
For my page theme swap project, I created four different color scheme layouts for the websites overall look and feel, so when the theme button was clicked the corresponding color theme would switch throughout the website. However in order to switch the theme on button click the page required a postback to fire the Page_PreInit method which assigned the selected theme in the session. I wanted the postback to switch the theme but stay on the current page the theme was switched from.



Solution:
protected void lbRed_Click( object sender, ImageClickEventArgs e) 
{ 
   Session[ "theTheme" ] = lbRed.AlternateText.ToString(); 
   Response.Redirect(Request.RawUrl); 
} 
To do a postback to the current page the theme was switched from, instead of redirecting away, I set the 'Response.Redirect' to postback to '(Request.RawUrl)', retrieving the current pages url.

Similar syntax allowed my admin content management section to apply the current theme in the session to the ajax editor design panel tool.

protected void Page_Load( object sender, EventArgs e) 
{ 
   string path = String .Format(
              "~/App_Themes/{0}/images/style.css" , Page.Theme);
 
   Editor1.DesignPanelCssPath = path; 
}

No comments:

Post a Comment