Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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 September 11th, 2010, 07:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It normally would indeed preserve the selected value. Not because of ViewState but because of control state as the selected value of the drop down list is submitted to the server when you choose a new item (Drop down list can preserve their value even when ViewState is turned off).

However, in this case, after you've selected a new item, the user is redirected to the same page. A redirect means a new GET request, and thus there is no previous state / selection.

Does this help?

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 September 11th, 2010, 07:32 AM
Authorized User
 
Join Date: Sep 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reply

OK this helped, but then why did we make the (!page.ispostback) we are posting back to the server, which means the code in the page_load is done only when the user opens the form, when he changes the drop down list, it won't go inside the IF condition, because it's a post back. right !?
 
Old September 11th, 2010, 07:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes correct.

If you leave out the !IsPostBack check, the code in Page_Load would also fire after you selected item in the drop-down list, but before SelectedIndexChanged fires that redirects the user. Without the check, the drop down list would be reset to the previous value from the cookie and the new value would never be applied. Just take out the check to see for yourself how it works...

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 September 11th, 2010, 03:50 PM
Authorized User
 
Join Date: Sep 2010
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you're the best :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
StyleSheetTheme in master page anujrathi ASP.NET 2.0 Professional 0 December 8th, 2006 04:03 AM





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