The C# code needed to copy the selected (Best web site)

The C# code needed to copy the selected value to the user s profile is simply this: Profile.PreferredTheme = ListBox1.SelectedValue; Another detail to think about here is the fact that when the user first opens the page, she will already have a theme name selected in her profile. Then the ChooseTheme page first opens; the ListBox control should show that current theme as the selected theme. So in the Page_Load event, you need some code to set the SelectedValue of the ListBox control to whatever is currently in the user s PreferredTheme property. Hence, the Page_Load event needs this statement: ListBox1.SelectedValue = Profile.PreferredTheme; But, as is often the case with page loads, we have to take postbacks into consideration. Every time the user clicks the ListBox control, that s going to cause a postback, as we really only want to load the preferred theme when the user first opens the page. So once again, we need some if not postback logic in the Page_Load event handler, as shown here (in C#): if (!Page.IsPostBack) { ListBox1.SelectedValue = Profile.PreferredTheme; } Applying a theme Given our whole approach to themes in this chapter, it stands to reason that whenever a page loads, its theme must be set to the user s preferred theme. To get that done in your code, simply set Page.Theme to the user s preferred theme. In C#, the code looks like this: Page.Theme = Profile.PreferredTheme; But, you can t set a theme in the Page_Load event because the theme has to be applied before content and controls are rendered on the page. The Page_Load event fires after all that stuff is done, which is too late to apply a theme. So use the Page_PreInitI() event handler instead. You won t necessarily find a predefined pre-init handler in the page. But you can just copy and paste one of the existing handlers into the code and change its name to Page_PreInit. Then type in the code to apply the preferred theme, as given here: protected void Page_PreInit(object sender, EventArgs e) { Page.Theme = Profile.PreferredTheme; } 214 Part III: Personalization and Databases
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Leave a Reply