Monthly Archives: August 2009

Monthly Archives: August 2009

Fill PDF Form Fields from an ASP.NET page using iTextSharp

Posted on by Joe in ASP.NET, C# | 2 Comments

Download the source code: PDFTest.zip For a project I’m working on I needed to be able to generate PDF’s containing data from my page.  I came across a library called iTextSharp which is a C# port of the Java library iText.  Using this library allows you to generate PDF files on the fly.  You can download the library here, and need to add it as a reference in your project. In Adobe Acrobat I created a rather crude looking PDF with two …

Using the CustomValidator’s ClientValidationFunction

Posted on by Joe in ASP.NET, C#, JavaScript | 2 Comments

The ASP.NET CustomValidator allows you to create custom validation that fits into its validation framework.  The CustomValidator has a server side event called OnServerValidate and a client side event called ClientValidationFunction. You can use the CustomValidator by just implementing the OnServerValidate event, but any other validation controls that are validated client side will need to be valid before the CustomValidator will be used.  Doing this causes a postback to validate the CustomValidator and as it’s not client side the validation …

Show a JavaScript confirm dialog box after client validation

Posted on by Joe in ASP.NET, C#, JavaScript | 6 Comments

It’s quite common to use a JavaScript confirm dialog on a button press to ensure that the user wants to submit the page.  If you are using any of the ASP.NET validators that use client side validation you will find the confirm appears before the validation, whereas it would be better if the confirm box only appeared if the page was valid. Luckily the framework supplies some JavaScript functions that can be used for validation.  Page_IsValid is a boolean indicating …

Generate a CSV from a generic list of objects using reflection and extension methods

Posted on by Joe in ASP.NET, C# | 9 Comments

Download the source code for this post: ReflectionCSV.zip Last week I wrote a post about generating a CSV from a DataTable. As I hardly use DataTables these days I thought it would be good to write a function that does this for a generic list of objects using reflection to get the properties of the object and export them. In this example I have done this using an extension method on the generic list. This approach could also be easily …