Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 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 November 30th, 2008, 05:37 PM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default BrowseArticles.aspx Page Problem

Following through Marco's code in the book, I've reached Chapter 5: News and Article Management. There is an end-user page, BrowseArticles.aspx, that is implemented by using the ArticleListing.ascx user control. This is the exact same control that is used in the ManageArticles.aspx Admin page.

I've added the control to the BrowseArticles.aspx page, but a strange thing seems to be happening. When I navigate to BrowseArticles.aspx from ShowCategories.aspx, it displays the articles from the category specified by the CatID on the query string, which is fine. The strange occurrence is that if I then switch Categories to 'All Categories' via the drop down list, the GridView in the ArticlesListing control displays the empty message (no articles to show).

Any idea what could be happening here? This problem does not arise when I use the control in the ManageArticles.aspx Admin page.
 
Old November 30th, 2008, 05:58 PM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I got it. It was that I needed a code branch in the SqlArticlesProvider class. In that class's GetArticles(bool publishedOnly, int categoryID, int startRowIndex, int maximumRows) overload, I checked for the publishedOnly value, and if it was false, I delegated to the GetArticles(int categoryID, int startRowIndex, int maxiumumRows) overload.

However, I didn't check for the case: publishedOnly is true, and categoryID is less than or equal to 0. So, what ended up happening was a call to the database querying for articles with CategoryID 0, which of course, don't exist. What the call should be is: if publishedOnly is true, and categoryID is less than or equal to 0, retrieve all published articles for all categories. Here is the fixed code:

Code:
public static List<Article> GetArticles(bool publishedOnly,
            int categoryID, int startRowIndex, int maximumRows)
        {
            if (!publishedOnly)
            {
                return GetArticles(categoryID, startRowIndex, maximumRows);
            }
            else
            {
                if (categoryID <= 0)
                {
                    return GetArticles(publishedOnly, startRowIndex, maximumRows);
                }
            }
    //otherwise, get all published articles for the specified (non-zero) category...
}
 
Old November 30th, 2008, 07:27 PM
Authorized User
 
Join Date: Nov 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, the above code fix is applied to MB.TheBeerHouse.BLL.Articles.Article class, not the SqlArticlesProvider as I had mentioned.





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem defining namespace for .aspx page pratik28 ASP.NET 2.0 Basics 0 October 26th, 2006 06:43 AM
Getting problem while running an aspx page manoj.mohanty BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 May 3rd, 2006 07:29 AM
How to pass variables from Aspx page to Asp Page jayaraj Classic ASP Basics 2 May 23rd, 2004 06:56 AM
How to pass the variables in Aspx page to Asp Page jayaraj ASP.NET 1.0 and 1.1 Basics 3 May 23rd, 2004 06:55 AM





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