Monday, June 21, 2010

News Feed - Web User Control

This is very simple code to create web user control to display News Feeds. Using this user can change properties of News Feeds and set his/her own url, number of news to display.

This code is developed in ASP.NET using C#, JavaScript and Simple HTML.

Lets step by step develop web user control for feeds

--------------------- Step 1 --------------------------------
Create one Web User control Named NewsFeed. Copy Past following code in C# file i.e. in ascx file. Just check out Properties in the code.



--------------------- Step 2 --------------------------------
Here we will use google code to read feeds and retrieve data. For more information you can check Google Code.

Put following Code in HTML view of same Web User Control. Following code will include google JSAPI file in your code, and it will load Google Ajax Feed API.



--------------------- Step 3 --------------------------------

We will use following code to set properties of Web User control in javaScript. Check out variables "feedUrl" , "feedNumber"; these variables are set in ASCX file. "feeddiv" is a div tag set in above code. We will display our feed in this div tag.



--------------------- Step 4 --------------------------------

Following code takes care of Feeds retrieval, and manipulate HTML which we are suppose to display in Div tag discussed above.

"display" feed function automatically get called once we retrieve feeds using googleFeed.

"errMessage" is set in ASCX page. Which can be set as property of Web User Control.


 

This is very simple code to develop. Any one with basic understanding of HTML, JavaScript and ASPX can develop web user control to display Feeds.

Download Demo Code here --> NewsFeeds.zip
Submit this story to DotNetKicks

1 comments:

Unknown September 26, 2010 at 10:37 AM  

excellent work - exactly what I was looking for. much obliged!