Wrox Programmer Forums
|
ASP.NET 4.5 General Discussion For ASP.NET 4.5 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5 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 April 24th, 2013, 09:32 AM
Registered User
 
Join Date: Apr 2013
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Paging random data

I’m a newcomer to ASP.NET (3 months) so am unsure how to solve this problem…

I run a village website which has about 60 advertisers. The details of the advertisers are held in the SQL Server database that holds other information about the site.
One of the pages shows all 60+ adverts in a gallery, using an ASP.NET ListView control.
To avoid any advertiser being ‘top of the list’, the sequence of adverts is deliberately randomised on every visit using ‘ORDER BY NEWID()’ in the SQL retrieval statement.

I’d like to reduce this long page to show only 6 at a time, with buttons to navigate back and forth, and have done this with a DataPager control and AJAX to minimise flicker (pages 544-549 of Imar's Beginning ASP.Net 4.5 book)

However, when I page back and forth the pages show different content each time. Clearly the ‘randomise’ effect is being called on every load/postback of the page.

Though I’m savvy enough to, say, write a stored procedure to generate a separate randomised SQL table on a scheduled basis and using that instead, it seems like a sledgehammer to crack a nut.
I’m guessing there must be some way of retrieving the 60+ records (4 brief text fields each) then storing them in a randomised way ‘local’ to the user, so that paging back and forth maintains the sequence.
Despite trawling the web, I’ve not come across anything that has helped. Paging- yes, randomising – yes. But not both together.
Either there’s something simple and obvious I’m missing, or this truly is a tricky puzzle.

I’m not looking for someone to write the code/markup for me, simply to suggest what approach is needed and, perhaps, where I might find reference material to help me put the code together.
The software/architecture I use includes MS Expression Studio 4 Web Professional, Visual Studio Express 2012 for Web, SQL Server 2008 and ASP.NET 4.5 with VB.

Phil.
 
Old April 25th, 2013, 03:09 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 Phil,

You could store the data retrieved from the database in a user specific store such as session state. On the first request, you get the data from the database and store it, on subsequent requests you get the data from session state instead. If the data you need to access is large, you could store the unique IDs of the sorted data in session state and use that to retrieve more data on further requests.

For this to work, you need to write some custom code. Rather than using a SqlDataSource control, you need to write your own code using, say, the Entity Framework to get your data out of the database and store it in session state.

Does this help? Let me know if you want to see some "pseudo" code to make this work.

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!
The Following User Says Thank You to Imar For This Useful Post:
pjskeldon (April 25th, 2013)
 
Old April 25th, 2013, 10:43 AM
Registered User
 
Join Date: Apr 2013
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks Imar - that was quick!

I've not used the Entity Framework before, so let me do a bit of reading around first. If I'm still stumped I'll ask you for that pseudo-code.

Again, many thanks. Your books have helped me pick up ASP.NET in just a few weeks!

Regards,

Phil.
 
Old April 25th, 2013, 11:09 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> Your books have helped me pick up ASP.NET in just a few weeks!

If you have the 4.0 or 4.5 version of the book, there's a whole chapter devoted to EF.

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 May 6th, 2013, 03:06 PM
Registered User
 
Join Date: May 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I like to lean more towards #4 as well because if we use flat-files, we will take the same performance hit as a cron job, but the flat-file guarantees that every time the pre-generated list is generated, a user will feel that performance hit, whereas a cron job will do it in the background, and for a user to feel that performance hit, they'd have to enter the site at that exact moment that database is being updated
 
Old May 8th, 2013, 08:07 AM
Registered User
 
Join Date: Apr 2013
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks for your responses. I've been enjoying something rare in Britain lately - some sunshine. Now I'm back on this!

Imar - I do have your '4.5' book so will read up on EF this afternoon and try it out. Though I've stripped the page down to the bare essentials, everything else I've tried so far has failed to crack this one, including VB to retrieve and bind the data in a DataTable on initial page load (as suggested by the Wrox 'Professional ASP.NET 3.5' book). It gets the data but then the paging doesn't work - advert images remain static, although the buttons 'work' as if (behind the scenes) it really is paging the data.

Rolling up my sleeves...

Phil.
 
Old May 8th, 2013, 08:49 AM
Registered User
 
Join Date: May 2013
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default

When a user comes in and clicks on the link, the items on the page should be randomized. As the user clicks on page two, three onwards, it should follow the same random pattern that it generated the first time so that when I go back to the first page the items on that page would be same as when the user first clicked on the link.
 
Old May 8th, 2013, 01:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Let me know if you get stuck and I'll try to cook up an example for you....

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 May 8th, 2013, 02:30 PM
Registered User
 
Join Date: Apr 2013
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks Imar.

I'm taking this slowly as I'm new to this.
Not only that but the original website was developed using Expression Studio 4 Web Professional. That doesn't seem to like recent ASP.NET syntax (perhaps limited by it being an older product) so I'm porting the whole thing to Visual Studio Express.

Of course in doing that I need to learn a new product (more time!) and, if I use any new features on ASP.NET, I'll need to migrate the website to the 4.5 model. I know the WEB.CONFIG is different and I've been reading up on using VS to do the transformation for me.

All in all, some work ahead of me! You can see why just setting up a stored procedure to create a daily random table seemed so attractive.

But then I wouldn't have bought so many books and wouldn't have learned anything new!

Now if only I could use COBOL...

Phil.
 
Old May 9th, 2013, 05:43 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
All in all, some work ahead of me! You can see why just setting up a stored procedure to create a daily random table seemed so attractive.
You could still do that and call it from custom code or EF.

But I thought you needed to randomize on "every visit"?

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 21: Try It Out: Writing Data to Random Access File malie22001 BOOK: Beginning Visual C# 2010 2 July 16th, 2012 03:26 AM
data paging rahulbedardi ASP.NET 4 General Discussion 0 March 19th, 2012 05:52 AM
Getting Data from a VB5 Random File lowell Visual Basic 2005 Basics 11 July 5th, 2007 05:39 AM
paging through data - Data Access Objects fedoracore PHP Databases 0 November 28th, 2006 07:54 PM
Help: dropdownlist posting back gives random data vickeyurs ADO.NET 5 September 3rd, 2005 09:28 AM





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