Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 July 29th, 2009, 11:16 AM
Authorized User
 
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selecting Theme in DropDownList

First I really like your book. Excellent.

I had some strange behavior with selecting my theme. It was working, I could select between the themes. Then (I must have done something) it stopped working and would only show the grey theme. I double clicked the dropDownlist in design view expecting to go to SelectedIndexChanged event but instead it added another one called ..SelectedIndexChanged1. So I copied the code from SelectedIndexChanged into this new event and everything works. Do you know why this would happen? If I double click on a control it should take me to the control's event and not create a new one right?

Also, I'm using VS2008 professional edition with service pack1 on Vista ultimate and it crashes occasionally, esp. if I undock windows and then switch views. The above happened after the IDE crashed.

Code:
 protected void lstPreferredTheme_SelectedIndexChanged(object sender, EventArgs e)
    {
      // Retrieves the selected theme from a DropDownList and stores it in a cookie.
      HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
      // set cookie to expire in three months. If user selects again then saves agian.
      preferredTheme.Expires = DateTime.Now.AddMonths(3);
      preferredTheme.Value = lstPreferredTheme.SelectedValue;
      Response.Cookies.Add(preferredTheme);
      // Redirect the user to the same page. This is necessary because otherwise the new theme won't
      // be applied immediatly since the theme needs to be set early in the page's life cycle. By
      // redirecting a new request is made which can successfully applyl the selected theme.
      Response.Redirect(Request.Url.ToString());
    }
    protected void lstPreferredTheme_SelectedIndexChanged1(object sender, EventArgs e)
    {
      // Retrieves the selected theme from a DropDownList and stores it in a cookie.
      HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
      // set cookie to expire in three months. If user selects again then saves agian.
      preferredTheme.Expires = DateTime.Now.AddMonths(3);
      preferredTheme.Value = lstPreferredTheme.SelectedValue;
      Response.Cookies.Add(preferredTheme);
      // Redirect the user to the same page. This is necessary because otherwise the new theme won't
      // be applied immediatly since the theme needs to be set early in the page's life cycle. By
      // redirecting a new request is made which can successfully applyl the selected theme.
      Response.Redirect(Request.Url.ToString());
    }
 
Old July 29th, 2009, 11:40 AM
Authorized User
 
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default I think I know what happened. Just not how.

I think somehow the SelectedIndexChanged in the properties events window was cleared out. I cannot replicate it anyother way i.e. when I double click on the theme dropdown in design it brings me to my event. I deleted my SelectedIndexChanged1 and "rewired" to SlectedIndexChanged and everything is back to normal. It's strange that it would clear the event in the first place.
 
Old July 29th, 2009, 12:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, I've seen that a few times before as well. Here's how I can reproduce it:

1. Add a DDL in Design View

2. Double click the DLL to setup the handler and go to the Code Behind

3. Save all your changes

4. Go to the Markup and press Ctrl+Z once to undo your changes. This removes the handler from the DDL markup, but not from the code behind.

5. Save again.

6. Double click the handler again in Design View. VWD sees the existing handler, and thus creates a new one with a sequential number.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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 July 29th, 2009, 01:51 PM
Authorized User
 
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selecting Theme in DropDownList

You refreshed my memory. I was playing around in the markup and I did quite a few Ctrl z's. Good to know.

Thanks Imar.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Theme (chpater 2) yevi BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 March 22nd, 2009 11:50 AM
Selecting DropDownList Item yes_no ASP.NET 1.0 and 1.1 Professional 1 April 8th, 2008 08:00 AM
Theme Selector wont pick up other theme Tawanda BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 May 4th, 2007 08:44 AM
theme selector rav BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 February 12th, 2007 12:44 AM
page theme zhugeliang ASP.NET 2.0 Basics 1 January 9th, 2007 02:40 AM





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