Developing an ASP.NET AJAX Based RSS Reader
page 7 of 10
by Xianzhong Zhu
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 38530/ 58

Displaying the RSS Channels

In this section of the RSS reader application there are at least two cases in connection with displaying the RSS channels.

1. When the page is first loaded all the RSS channels stored in the server-side SQL Server database should be displayed in the ListView control mentioned above.

2. When the user clicks the "Refresh" button all the original RSS channels' info in the server-side database should also be shown.

Examine the first case. The following Listing shows all the related xml-script code.

Listing 4

<script type="text/xml-script">
<span lang=FR><page xmlns:script=""></span>
            <dataSource id="RSSInfoDataSource" serviceURL="MyDataService.asmx" >
            <button id="Save">
                        <invokeMethodAction target="RSSInfoDataSource"
                            method="save" />
                        <binding dataContext="RSSInfoDataSource"
                            dataPath="isDirtyAndReady" property="element" 
                            propertyKey="disabled" transform="Invert" />
            <button id="Refresh">
                        <invokeMethodAction target="RSSInfoDataSource"
                            method="load" />
                        <binding dataContext="RSSInfoDataSource"
                            dataPath="isReady"  property="element"
                            propertyKey="disabled" transform="Invert" />
                        <invokeMethodAction target="RSSInfoDataSource"

Specify the DataSource control named "RSSInfoDataSource" which is asynchronously bound to the server-side DataService "MyDataService" through ASP.NET AJAX framework. Second, in the last <application> section when the application is started its event load is fired. Subsequently, in the sub section <invokeMethodAction> the load method of DataSource "RSSInfoDataSource" is invoked, which will trigger an asynchronous post back calling the WebMethod GetAllRecords of DataService "MyDataService." The following Listing shows the source code for this method.

Listing 5

public List<RssInfo> GetAllRecords()
      return new SqlTaskProvider().GetAllRecords();

For a detailed explanation of the attributes decorating the method and this method, please refer to my previous article published on  As soon as this method returns the client-side ListView control, "RSSNameList" is populated with the record data persisted in SQL Server database table "RssStore."

There is a little skill herein deserved to be further researched. To gain a better user experience we select to hide the unnecessary fields (Rss_ID and Rss_URL).  The following gives the related HTML code snippet.

Listing 6

<div id="searchResults_itemTemplate" >
      <span id="searchResults_Rss_ID" 
          style="display: none; visibility: hidden;"></span>
      <span id="searchResults_Rss_Name"></span>
      <span id="searchResults_Rss_URL" 
          style="display: none; visibility: hidden;"></span>

No worries. The framework will automatically discern this situation and still populate the ListView control with the database record data as usual, with only the two specified fields being hidden.  That is it!

Now, let us examine the second case when the user clicks the Refresh button.  Although literally we use the word "Refresh," the real purpose is to load the original data in the server-side database into the current ListView.  We should own this function to method load of the client-side DataSource control. The following xml-script code indicates to you the associated programming.

Listing 7

<button id="Refresh">
            <invokeMethodAction target="RSSInfoDataSource" method="load" />
            <binding dataContext="RSSInfoDataSource" dataPath="isReady"
                property="element" propertyKey="disabled" transform="Invert" />

As is easily seen, when the users click Refresh, method load of the client-side DataSource control "RSSInfoDataSource" is invoked. Next, you may have guessed the following things happen; the WebMethod GetAllRecords is asynchronously invoked and then the returned data is filled into the ListView control.

For integrity, in this sample application we have also introduced a Save button whose function is just contrary to that of the Refresh button. When the user clicks the Save, all the newest RSS channel data in the ListView control is persisted back into the server-side SQL Server database in AJAX way.  Again, we are not going to discuss it since my previous article brought a thorough examination with it.

View Entire Article

User Comments

Title: Trouble with Sample Code   
Date: 2009-04-09 3:28:34 PM
Hello Xianzhong, I recently downloaded your sample code, did a little alteration to it and then compiled it. When I went to view it in a browser, after clicking on the "Add the RSS info" button, I get a javaScript error.

var datatable =g_RSSNameList.get_data(); throws a null reference exception.

After 2 days of trying to debug this, I am finally contacting you. Any ideas on how to troubleshoot this?

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-06-17 7:20:38 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search