Justin Cooney

Web Development Tips and Examples

  • Personally, I love Regular Expressions. They are incredibly useful and can quickly turn a task that would take many lines of code into a single statement. They are perfect for text manipulation and forms processing & validation. In general they simplify the everyday coding lives of developers world-wide.

    However, Regular Expressions do come with a down-side. They can be complex to read and difficult to get ‘just right’. (more…)

  • I encountered a quirk today with pre-selecting a list item in the code-behind for a data-bound dropdown list during both the Page.Load and Page.PreRender events.

    I could set the selected value, but I could not check the list to see if the value that I wanted to select is actually available for selection. This is important in case there is bad data in the database… instead of having the page break I want the dropdown list to default to the first selectable option (or output a detailed error message depending on what makes the most sense).

    The page I was working on was a report that had a GridView control presenting the data, and had two bound dropdown lists that the user could use to filter the presented report. On the first load of the page I wanted to set the default selections in the dropdown lists based on the user’s geographic location. (more…)

  • Often I find that I need to display a date and/or time in a specific format. Luckily VB.NET provides many options to adjust how a date is rendered as a string.

    Today, for example, I was working on a Web-based report that can be exported as an Excel file. As part of the process I wanted the Date and Time to be appended as part of the file name, but without special characters such as hyphens or colons that might not be compatible with what Windows likes in a file name. With VB.NET this is easily done in one line:

    Dim strFileName As String = "ReportFile" & (DateTime.Now).ToString("yyyyMMddTHHmmss") & ".xls"

    This will output the file name as: ReportFile20110824T133027.xls. (more…)