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 February 8th, 2007, 08:15 PM
Registered User
 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default RssReader.ascx.cs error

I'm getting the following error when I try to load the RssReader.ascx control from my Default.aspx page. Here is the error:



Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 24: if (value.StartsWith("/") || value.StartsWith("~/"))
Line 25: {
Line 26: url = (this.Page as BasePage).FullBaseUrl + value;
Line 27: url = url.Replace("~/", "");
Line 28: }


Source File: c:\sdalternative_v2\Controls\RssReader.ascx.cs Line: 26

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   MW.Alternative.UI.Controls.RssReader.set_RssUrl(St ring value) in c:\sdalternative_v2\Controls\RssReader.ascx.cs:26
   ASP.default_aspx.__BuildControlRssReader1() in c:\sdalternative_v2\Default.aspx:5
   ASP.default_aspx.__BuildControlContent1(Control __ctrl) in c:\sdalternative_v2\Default.aspx:4
   System.Web.UI.CompiledTemplateBuilder.InstantiateI n(Control container) +32
   ASP.alternative_master.__BuildControlMainContent() in c:\sdalternative_v2\Alternative.master:170
   ASP.alternative_master.__BuildControlMain() in c:\sdalternative_v2\Alternative.master:41
   ASP.alternative_master.__BuildControlTree(alternat ive_master __ctrl) in c:\sdalternative_v2\Alternative.master:1
   ASP.alternative_master.FrameworkInitialize() in c:\sdalternative_v2\Alternative.master.cs:912307
   System.Web.UI.UserControl.InitializeAsUserControlI nternal() +46
   System.Web.UI.UserControl.InitializeAsUserControl( Page page) +35
   System.Web.UI.MasterPage.CreateMaster(TemplateCont rol owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +1206
   System.Web.UI.Page.get_Master() +72
   System.Web.UI.Page.ApplyMasterPage() +30
   System.Web.UI.Page.PerformPreInit() +48
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1446


Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using MW.Alternative.UI;

namespace MW.Alternative.UI.Controls
{
    public partial class RssReader : System.Web.UI.UserControl
    {
        public string RssUrl
        {
            get { return lnkRss.NavigateUrl; }
            set
            {
                string url = value;
                if (value.StartsWith("/") || value.StartsWith("~/"))
                {
                    url = (this.Page as BasePage).FullBaseUrl + value;
                    url = url.Replace("~/", "");
                }
                lnkRss.NavigateUrl = url;
            }
        }


        public string Title
        {
            get { return lblTitle.Text; }
            set { lblTitle.Text = value; }
        }

        public int RepeatColumns
        {
            get { return dlstRss.RepeatColumns; }
            set { dlstRss.RepeatColumns = value; }
        }

        public string MoreUrl
        {
            get { return lnkMore.NavigateUrl; }
            set { lnkMore.NavigateUrl = value; }
        }

        public string MoreText
        {
            get { return lnkMore.Text; }
            set { lnkMore.Text = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.RssUrl.Length == 0)
                    throw new ApplicationException("The RssUrl cannot be null.");

                // create a DataTable and fill it with the RSS data,
                // then bind it to the Repeater control
                XmlDataDocument feed = new XmlDataDocument();
                feed.Load(this.RssUrl);
                XmlNodeList posts = feed.GetElementsByTagName("item");

                DataTable table = new DataTable("Feed");
                table.Columns.Add("Title", typeof(string));
                table.Columns.Add("Description", typeof(string));
                table.Columns.Add("Link", typeof(string));
                table.Columns.Add("PubDate", typeof(DateTime));

                foreach (XmlNode post in posts)
                {
                    DataRow row = table.NewRow();
                    row["Title"] = post["title"].InnerText;
                    row["Description"] = post["description"].InnerText;
                    row["Link"] = post["link"].InnerText;
                    row["PubDate"] = post["pubDate"].InnerText;
                    table.Rows.Add(row);
                }

                dlstRss.DataSource = table;
                dlstRss.DataBind();
            }
            catch (Exception)
            {                
                {
                    this.Visible = true; 
                }

            }           
        }
    }
}
 
Old February 8th, 2007, 08:53 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

from where are you runing your application?

IIS or Virtual machine?

Did you read the book?



 
Old February 8th, 2007, 09:02 PM
Registered User
 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm running from the ASP.NET Development server. Yes I've read the book. I've managed to get to this point without any problems.

 
Old February 8th, 2007, 11:59 PM
Registered User
 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem solved.

I had the wrong Inherits location in my .master file.

 
Old April 16th, 2007, 04:14 AM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to doronkatz Send a message via Yahoo to doronkatz
Default

MW, what did you have in your master, how did you get it to work.
Cheers






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 Object reference error in master.cs mikeal_a BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 September 5th, 2008 07:19 AM
Problem with RssReader.ascx user control retroviz BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 24th, 2007 07:06 PM
Context.User in siteheader.ascx.cs scottf BOOK: ASP.NET Website Programming Problem-Design-Solution 7 November 3rd, 2005 12:52 PM
AssemblyInfo.CS Compile Error zamankazi BOOK: ASP.NET Website Programming Problem-Design-Solution 2 October 22nd, 2004 08:31 AM
Cannot compile siteheader.ascx.cs golfvilla BOOK: ASP.NET Website Programming Problem-Design-Solution 6 January 19th, 2004 06:27 PM





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