Why is the statement "if (!Page.IsPostBack)
" needed in the code below?
protected void Page_Load(object sender, EventArgs e)
string selectedTheme = Page.Theme;
HttpCookie preferredTheme = Request.Cookies.Get("Prefe
if (preferredTheme != null)
selectedTheme = preferredTheme.Value;
Theme) != null)
ected = true
This code is an event handler for a ListBox control named ThemeList. ThemeList lists two page style themes: Monochrome and DarkGrey. The theme is stored in a cookie. The user can dynamically switch between the two themes by choosing either Monochrome or DarkGrey from the list. The purpose of the event handler is to make sure that the user's choice becomes the selected item in the DropDownList.
I don't understand why if (!Page.IsPostBack
) is needed. If I run the program and keep switching between Monochrome and DarkGrey, isn't each change in the dropdownlist's selected value a postback?
The entire VWD project is attached--Planet Wrox.zip.