Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to MySQL server on 'localhost' (10061) in G:\PleskVhosts\miguelontheweb.com\httpdocs\wordpress\wp-content\plugins\easy-contact-forms\easy-contact-forms-database.php on line 152

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in G:\PleskVhosts\miguelontheweb.com\httpdocs\wordpress\wp-content\plugins\easy-contact-forms\easy-contact-forms-database.php on line 152
Post Json to Asp.net Page and Create PDF – Miguel On The Web

Post Json to Asp.net Page and Create PDF

I was in a pickle not to long ago and i wanted to simply take my html table and create a pdf out of it. In this first tutorial ill show you how to take the JSON and posted to a web page. Then from there you would be able to read that JSON using  a nifty library called JSON.net .  So without further ado lets get the show started. First things first  create your JSON perhaps your JSON might look something like this.

Well from here we need to figuered out how to post this to an asp.net page that would render the PDF for us. I thought and thought about this and decided well a web service would just not cut it so lets post the data over to another page using good old fashion Javacript.
Lets see what that might look like.

 

The code is documented is pretty straight forward we are creating a form element assigning some form attributes like posting action and name and then submitting the form with the JSON as the value of the input element in the form.

After thats is done we need to intercept the data in the ASP.NET code behind page.  Lets tackle that now.

First things first make you are download JSON.net once you download it add a reference to the Newtonsoft.json.dll.

so far so good , now for the actual c#. Make sure you create another page in  your site and in the page load event we are going to apply the

following code.

 

Lets walk through this quickly. WE added reference to the JSON.net library. Then we made a DATA class that we assign a property the same as the JSON property. JSON.net then parses that into the data object for you. It really does all the heavy lifting for you.  Its quite remarkable.

That’s all  for now next post i will add the looping of the data class and then actually creating the pdf right in front of your eyes.

 

Leave a Reply

Your email address will not be published. Required fields are marked *