Handling Articles and Categories for an ASP.NET AJAX Client-Centric Wiki Application - Display the Article Categories
(Page 2 of 4 )
In fact, this part has already been shown at the right side of the homepage. And also, we know that when clicking an item under ‘Sections’ the user will be navigated to another page, namely ‘MsgList.aspx,’ which will show the more detailed article category information. In this section, we will continue to discuss it.
First, let’s take a quick look at the design-time snapshot, as is shown in the following Figure 10.
Figure 10—the design-time snapshot of page MsgList.aspx.

You can see that only a few controls are put on the page: two HTML <a> elements (with each containing an <img> element) at the top and bottom respectively for the writer’s convenience, a MS AJAX ListView control occupying the larger middle space, and a line or footnote at the far bottom of the page.
Note here that we have to combine the xml-script mode with the imperative JavaScript mode. There are two reasons for this. On the one hand, when the user clicks the hyperlink ‘Write a New Post’ we have to dynamically decide if he or she is a valid user so as to take the corresponding actions. On the other hand we have to dynamically load the DataSource that will be bound to the ListView control according to the different article category information the user has selected at the homepage.
Now, let’s see the related code snippet. First, at the end of the xml-script part we define the following:
<application load="onLoad">
</application>
Here we have not immediately called the load event of the data source ArtInfoDataSource when the application is loading but bound a client-side function onLoad to the load event of the Application object. A clever reader may have doped out that only in this way can we achieve our goal—dynamically loading the data source. The following gives the code for the onLoad function:
function onLoad(sender,args)
{
g_ArtInfoDataSource= $find('ArtInfoDataSource');
var paraCategoryID=getParm();
if (paraCategoryID!=null) {
g_ArtInfoDataSource.get_parameters()["CategoryID"] =paraCategoryID+1;
g_ArtInfoDataSource.load();
}
}
function getParm()
{
var url=this.location.href;
var pageurl = url.substring(url.indexOf("=")+1);
return parseInt(pageurl);
}
As you can see, we first ‘$find’ the data source control, then with a helper function named getParm we get the passed parameter (i.e. ‘CategoryID=x’) that is specified in the homepage, then we get and specify the exact value of the CategoryID field of the data source, and at last we can succeed in loading our data source.
As for the ‘Write a New Post’ hyperlink, it’s pretty easy. When you click the hyperlink, it calls the following function:
function judge(){
var bAuthenticated = <%= Page.User.Identity.IsAuthenticated.ToString().ToLower() %>;
if (bAuthenticated){
window.location.href='SendMsg.aspx';
}
else {window.location.href='login.aspx'; }
}
First, with the help of the special ASP.NET <% %> block, we can call the server-side method and get the related value to mark when the current user has been authenticated (note the current user related info is stored in the ASPNETDB.MDF database). If the user is a valid user, then we allow him to write a new post (i.e. article) by redirecting him to the SendMsg.aspx page; otherwise, we lead him back to the login page.
In the next section, we will start to look into another more interesting and challenging topic—displaying an article asynchronously.
Next: Display an Article Asynchronously >>
More ASP.NET Articles
More By Xianzhong Zhu