The Beer House Starter Kit Web Parts

Last post 04-21-2008 1:54 PM by TheEagle. 7 replies.

Sort Posts:

  • The Beer House Starter Kit Web Parts

    04-17-2008, 2:21 PM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    Hi,

    I have a problem with the RssReader when I put it in the DeclarativeCatalogPart and then try to add it (at runtime) to a WebPartZone I get the exception:  rss url cannot be null.When I put the same RssReader usercontrol outside the catalog zone it works fine.In both cases I set the RssUrl property to "~/GetArticlesRss.aspx".Please help me to solve this problem.

  • Re: The Beer House Starter Kit Web Parts

    04-17-2008, 3:49 PM
    • Loading...
    • Lee Dumond
    • Joined on 11-03-2004, 10:51 AM
    • Decatur, IL USA
    • Posts 854

    Seems weird to me. Check the code-behind of your Rss Reader user control (RssReader.ascx.cs). There should be a Page_Load method. Post your Page_Load method from this file and let us have a look at it.
     

    // ******************************
    if (this.PostHelpedYou)
    {
    MarkAsAnswer();
    }
  • Re: The Beer House Starter Kit Web Parts

    04-17-2008, 4:18 PM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    Thank you for your respond... 

    The code you requested:

     

      public RssReader()
            {
    
                this.Title = "RSS Reader";
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                DoBinding();
            }
            protected void Page_PerRender(object sender, EventArgs e)
            {
                DoBinding();
            }
    
            protected void DoBinding()
            {
                if (this.RssUrl.Length == 0)
                    throw new ApplicationException("Rss url cannot be null!");
                XmlDataDocument feed = new XmlDataDocument();
               
                    
                    feed.Load(GetFullUrl(this.RssUrl));
                XmlNodeList posts = feed.GetElementsByTagName("item");
                DataTable tb = new DataTable("Feed");
                tb.Columns.Add("Title",typeof(string));
                tb.Columns.Add("Link", typeof(string));
                tb.Columns.Add("Description", typeof(string));
                tb.Columns.Add("PubDate", typeof(DateTime));
                foreach (XmlNode node in posts)
                {
                    DataRow row = tb.NewRow();
                    row["Title"] = node["title"].InnerText;
                    row["Link"] = node["link"].InnerText;
                    row["Description"] = node["description"].InnerText.Trim();
                    row["PubDate"] = DateTime.Parse(node["pubDate"].InnerText);
                    tb.Rows.Add(row);
                }
                dlstRss.DataSource = tb;
                dlstRss.DataBind();
            }
            private string GetFullUrl(string url)
            {
                if (url.StartsWith("/") || url.StartsWith("~/"))
                {
                    url = (this.Page as BasePage).FullBaseUrl + url;
                    url = url.Replace("~/", "");
                }
                return url;
            }
            [Personalizable(PersonalizationScope.User),WebBrowsable,WebDisplayName("Rss Url"),WebDescription("The Url of the RSS feed")]
            public string RssUrl
            {
                get { return lnkRss.NavigateUrl; }
                set
                {              
                        lnkRss.NavigateUrl = value;
                  
                }
            }
     
  • Re: The Beer House Starter Kit Web Parts

    04-17-2008, 4:55 PM
    • Loading...
    • Lee Dumond
    • Joined on 11-03-2004, 10:51 AM
    • Decatur, IL USA
    • Posts 854

     There's a typo in this code:

    protected void Page_PerRender(object sender, EventArgs e)
    {
    DoBinding();
    }

     

    // ******************************
    if (this.PostHelpedYou)
    {
    MarkAsAnswer();
    }
  • Re: The Beer House Starter Kit Web Parts

    04-17-2008, 6:40 PM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    I fixed this type error(Per to Pre) it is strange why didn't the compiler notify me for it?.

    But the problem still as it is before(the exception is fired again when I add the RssReader WebPart to a WebPartZone at runtime).  

    Sometimes a series of errors appear about the RssReader and the PollBox user controls) but when I rebiuld the solution all of them disappear. 

  • Re: The Beer House Starter Kit Web Parts

    04-17-2008, 7:05 PM
    • Loading...
    • Lee Dumond
    • Joined on 11-03-2004, 10:51 AM
    • Decatur, IL USA
    • Posts 854

     

    TheEagle:
    I fixed this type error(Per to Pre) it is strange why didn't the compiler notify me for it?.
     

    The compiler doesn't care what you call a method. The only reason we use Page_PreRender in this case is so that the runtime can use the AutoEventWireup to connect this so-named method to the PreRender event behind the scenes. If you wanted, you could instead use a delegate to map the page's PreRender event to a method with any name you choose, like protected void ThisIsMyPreRenderMethodBlahBlahBlah(object sender, Eventargs e). The compiler has no way of knowing what your intention is, so it doesn't check.

    Your code seems okay to me. But, for some reason, it is throwing the ApplicationException you set up:

    if (this.RssUrl.Length == 0)
    throw new ApplicationException("Rss url cannot be null!");

     

    This means it is seeing a Length of 0 in your RssUrl.

    If it were me, I'd first try running the application straight from the download. That should definitely work.

    Then, debug through the "working" code line by line, so you can see how it executes. It might help to set a Watch on RssUrl.Length.

    Then, do exactly the same in your own code, and see how the program execution differs.

    The big advantage we have in debugging this app is that we have a 100% certified working version we can always refer to.

    // ******************************
    if (this.PostHelpedYou)
    {
    MarkAsAnswer();
    }
  • Re: The Beer House Starter Kit Web Parts

    04-20-2008, 4:11 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    Iam trying to perform your idea but the beer house solution has many rss webparts which make it taking very long time to go line by line.I have debug my solution for one rssReader control as a webpart and add it to a zone.First RssUrl property set section is hit then the get section is hit and return lnkRss.NavigateUrl as "" like if it was not set to the value "~/GetArticlesRss.aspx".Then the get section is hit again with the same result.Then the complier goes to the Page_Load where the DoBinding method exist then the exception is thrown.

     When entering the catalog mode only the set section is hit(the get section is not hit).

    Hope that you can help me to find what is happening because I really don't know what to do and what is happening.

  • Re: The Beer House Starter Kit Web Parts

    04-21-2008, 1:54 PM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128
    Now the situation is more clear.I made another line by line debug.I found the the RssUrl property is set (lnkRss.NavigateUrl) correctly but after the compiler go to set the BaseWebPart properties the lnkRss.NavigateUrl is forgotten.I don't know why?!

      

Page 1 of 1 (8 items)