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.