Wrox Programmer Forums
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 19th, 2016, 07:42 PM
Authorized User
Join Date: Aug 2015
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
Default DropDowns and Post Back

I have 2 dropdown lists. The second one is filled based on the selection in the first. I am using Autopostback = true and onselectedindexchanged in the first one to fill the second. It works fine except ... If I make a selection in the first dropdown so the second one is filled, and then go back and make a different selection in the first, the values from my original selection stay visible in the second. What do I need to do to refresh the data in the second dropdown?

Thank you.
Old February 21st, 2016, 08:33 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

Is this related to a specific exercise in the book? If so, which chapter / page number does this refer to? And if not, you're better off posting this in the general ASP.NET category here: http://p2p.wrox.com/asp-net-4-5-709/

That said, depending on how you set up stuff you may need to call DropDown2.Items.Clear() or DropDown2.Bind() to get rid of the items.


Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Old June 1st, 2016, 12:38 AM
Registered User
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default CH 6

I am having the same issue. This is Chapter 6 Page 239.

After following the instructions and even copy and paste the code from the source to the one I am creating still does not change the theme.

Any ideas or suggestions??

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPages_Frontend : System.Web.UI.MasterPage
    protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
            string selectedTheme = Page.Theme;
            HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
            if (preferredTheme != null)
                selectedTheme = preferredTheme.Value;
            if (!string.IsNullOrEmpty(selectedTheme))
                ListItem item = ThemeList.Items.FindByValue(selectedTheme);
                if (item != null)
                    item.Selected = true;

    protected void ThemeList_SelectedIndexChanged(object sender, EventArgs e)
        HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
        preferredTheme.Expires = DateTime.Now.AddMonths(3);
        preferredTheme.Value = ThemeList.SelectedValue;
Old June 1st, 2016, 01:51 PM
Registered User
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Found the solution.

I think I was reading too fast and not paying attention to the details.

CH6 Page 242 step 6 it says on the botton "Notice that you keep seeing the same theme because you haven't written any code yet that applies the selected theme"

Page 243 shows how to do this code but step 4 (page 244) shows the reasons of why it might not work.
*Web.Config needs to be changed
*The most important Default page the Code behind needs to point to BasePage and not the default one.

Similar Threads
Thread Thread Starter Forum Replies Last Post
post back SKhna ASP.NET 2.0 Basics 1 March 10th, 2008 09:23 AM
post back k.manisha ASP.NET 1.0 and 1.1 Professional 2 February 7th, 2007 02:28 PM
Why does the form always post back? Conch General .NET 9 January 9th, 2007 04:12 PM
Post Back rngrmn Pro VB.NET 2002/2003 1 May 5th, 2006 11:21 AM
Post Back rngrmn VB.NET 2002/2003 Basics 2 April 6th, 2006 01:14 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.