Justin Cooney

Web Development Tips and Examples

  • Today Luvy and I looked at updating the logic for an ASP.NET forms page that we are working on. The page contains a multi-row update-able GridView, and we were asked to make sure that if one CheckBox control was unchecked, that another CheckBox  control on the same grid line would also uncheck itself.

    We chose to handle this logic at the client side via JavaScript since a postback would certainly be overkill for handling such a straightforward rule.

    When adding JavaScript to an ASP.NET control there are two ways to do so. A JavaScript onClick event cannot be added directly to the HTML markup for the control, so the options are to add the JavaScript event either in the .NET control’s Render event, or to instantiate & update the control in the GridView’s Render event.

    In our case, we are performing a number of control adjustments in the GridView’s Render event, and I like to keep GridView logic in one place for readability reasons. So we went with the option of instantiating & updating the control in the GridView’s Render event rather than the CheckBox control’s Render event.

    To summarize the code, it went something a little like this: (more…)

  • Overview:

    The latest versions of Excel (2007, 2010) differ from Excel 2003 in their support of streaming a HTML document containing Excel-specific markup. Although core markup features still work, some of the previously supported functionality has now been removed.

    This directly affects the ability in code to stream a table to Excel and then use MSO tags to format the layout.

    In the more recent versions of Excel (2007, 2010) Microsoft has reworked their support for streaming Excel information on the Web and has added refined control over the ability to create an Excel document with a series of worksheets. But sadly with each new version of Excel they are removing much of their support for streaming HTML information to the browser that worked so well for Web developers in the past.

    Instead, when using the newer Microsoft syntax, a temporary file must be saved to the server before it can be sent to the browser. Further, using the new Microsoft method one cannot simply send an HTML table, but must re-query the database, and then re-generate the entire document.

    In this article I cover the tried-and-true method of streaming Excel directly to a client’s browser and explain what Excel markup still works, and what doesn’t.  I will cover the newer method of doing so in a future article.

    If you are interested in further background on this topic or useful links please see Part 1 of this article at: Generating Excel documents through HTML, XML, and CSS – Part 1

    How to Stream the Excel Document Directly:

    I recently had the requirement to output an ASP.NET GridView report in Excel, but additionally with the following Excel formatting requirements:

    • Print in Landscape layout
    • Add a detailed header to each printed page
    • Add a detailed footer to each printed page
    • Show Excel Rows and Columns on each printed page
    • Freeze the header table row when paging through Excel
    • Show the frozen header table row on each printed page
    Using the Excel 2003 document markup tags I am able to make each of these requirements visible in Excel regardless of the version. However some of the requirements make the printing process fail when trying to print with Excel 2007 or Excel 2010 (Excel 2003 of course works just fine).

    The requirements that cause the printing process to fail with Excel 2007 or Excel 2010 are:

    • Show Excel Rows and Columns on each printed page
    • Freeze the header table row when paging through Excel
    • Show the frozen header table row on each printed page
    So without further ado, here is the code that still works in all versions of Excel (more…)
  • Classic ASP Revisited
    Classic ASP Revisited

    Recently I was asked to update our homegrown timesheet application that had been written years ago in classic ASP. The update was simply to take a user name in the string format ‘Last Name, First Name’ and convert this to our company standard email format of FirstLetterofFirstName + LastName + @companyname.com

    Now it has been years since I wrote any classic ASP, so it took a little bit of looking into the various functions to refresh my memory.

    I made use of the following Classic ASP functions:

    • On Error Resume Next – to imitate standard try – catch block behavior
    • The Split(BaseString, Separator) function to separate the name string
    • The Left( function to get the first letter of the first name from the string array
    • The UBound( function to get the last entry in the name array
    • The Replace(BaseString, StringToBeReplaced, ReplacementString)
    • The LCase( function. Alternately I remember also finding the UCase function to be quite useful on occasion.

    Here is a test version of the code snippet I ended up using: (more…)