Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion 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, 2011, 09:43 PM
Registered User
 
Join Date: Jul 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Question about variable persistance

Hello, I am a WinForms Developer migrating to Web Development. I am specifically migrating to ASP.NET Web Forms at the moment. My only experience with Web Development at this point is from a couple of books.

Here is a problem that was never an issue for me in WinForms. Hopefully, someone can point me in the right direction.

Let's say you have a search screen for employees. You are not allowed to display anything that could be used as a unique identifier for each record in the grid on the screen. You are only allowed to diplay the name of the employees on the screen. When a user selects a record in the grid, you take the Employee ID of the selected record and search the datase.

The screen can be filtered. The user loads all 25 records for the employees in a certain Department. 17 of those 25 employees in that Department have the name of John Henry Smith. The user filters the list down to 3 records by searching for the last name of Johnson within the Department. You store those 3 records in a session variable for later use. The user then hits the Internet Explorer back button, pulling the previous screen out of the cache and simply dumping it onto the screen with all of the records displayed. The user then selects one of the employees named John Henry Smith, who happens to be the 20th record in the grid. You can't rely on Session variables, because that list only contains 3 records, none of which are the record you're looking for. You can't pull the Employee ID off the screen because you are not allowed to cheat and display it on the screen. Where do you get the Employee ID to search the database with?

Last edited by SillyPants; July 29th, 2011 at 09:47 PM..
 
Old July 30th, 2011, 05:22 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

If by Grid, you mean GridView, you can keep track of the associated primary key using DataKeyNames and DataKeys.Then when you select a record in the GridView, you can retrieve the key based on the zero-based index of the selected item. This way, the ID is not visible on screen, but it is available in a hidden and encoded field in the page.

Hope this helps,

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 August 1st, 2011, 10:53 AM
Registered User
 
Join Date: Jul 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
variable question nulogix PHP How-To 1 June 25th, 2004 02:35 PM
Printer Page Persistance greybeard C# 0 August 24th, 2003 11:08 PM
.Net User Controls - Property Persistance Prob Subhash1275 VS.NET 2002/2003 0 August 15th, 2003 04:03 AM





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