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

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="http://schemas.microsoft.com/xml-script/2005"></span>
      <components>
            <dataSource id="RSSInfoDataSource" serviceURL="MyDataService.asmx" >
            </dataSource>
 
            <button id="Save">
                  <click>
                        <invokeMethodAction target="RSSInfoDataSource"
                            method="save" />
                  </click>
                  <bindings>
                        <binding dataContext="RSSInfoDataSource"
                            dataPath="isDirtyAndReady" property="element" 
                            propertyKey="disabled" transform="Invert" />
                  </bindings>
            </button>
            <button id="Refresh">
                  <click>
                        <invokeMethodAction target="RSSInfoDataSource"
                            method="load" />
                  </click>
                  <bindings>
                        <binding dataContext="RSSInfoDataSource"
                            dataPath="isReady"  property="element"
                            propertyKey="disabled" transform="Invert" />
                  </bindings>
            </button>
 
            <application>
                  <load>
                        <invokeMethodAction target="RSSInfoDataSource"
                            method="load"/>
                  </load>
            </application>
      </components>
</page>
</script>

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

[WebMethod]
[DataObjectMethod(DataObjectMethodType.Select)]
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 aspalliance.com.  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>
</div>

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">
      <click>
            <invokeMethodAction target="RSSInfoDataSource" method="load" />
      </click>
      <bindings>
            <binding dataContext="RSSInfoDataSource" dataPath="isReady"
                property="element" propertyKey="disabled" transform="Invert" />
      </bindings>
</button>

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   
Name: fab.silva1119@gmail.com
Date: 2009-04-09 3:28:34 PM
Comment:
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 ASPAlliance.com  |  Page Processed at 2024-03-28 8:05:50 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search