Wednesday, September 28, 2005
Blogs.genesissys.com is a custom blogging engine, built in house to be both easy to use, and more importantly, easy to integrate into the newly redesigned GenesisSys.com website. As such, each required component of a "standard" blog engine had to be recreated, including the ubiquitous blog post calendar.
I'm consistently amazed by Ajax technologies, and by the people who seamlessly and integrate it into everyday use. Naturally, there are the obnoxious examples, but the truly remarkable samples are the ones that are nearly transparent. In setting out to add the calendar to the Genesis Blogs, I wanted the Ajax to be completely un-noticeable.
Consequently, I set out to develop a more Ajax-esque solution, and as it turns out, with just a little effort one can easily modify Ajaxify the ASP.NET calendar.
In essence, my idea was to have the page make an Ajax request for the Calendar's HTML, and would replace a div's innerHTML with the rendered calendar. Clicking "Next Month" would make another call, requesting the code-behind to render the next month, etc, etc.
Public Function GetCalendar(ByVal m As Integer, ByVal year As Integer) As String
Inside of this function, we simply need to create a calendar, render it to a string, and return the string.
Dim c As New Calendar
c.TodaysDate = month & "/1/" & year 'display the requested month...
Dim s As New StringBuilder
Dim sw As New StringWriter(s)
Dim tw As New HtmlTextWriter(sw)
We then call this function from the html with the following call:
function GetCal(month, year)
var divCalendar = document.getElementById('divCalendar');
var res = TestPage.GetCalendar(month, year);
if(res.error == null)
divCalendar.innerHTML = res.value;
alert('Error: ' + res.error);
"," & IIf(m = 12, year + 1, year) & ");"">></a>"
"," & IIf(m = 1, year - 1, year) & ");""><</a>"
Viola! A simple Ajax calendar! All that remains to do is to style the calendar appropriately, and to mark any special dates, and both of these things have been outlined elsewhere.
Lead Software Developer