C# From Plain Old Html

I dug up the code I wrote for DNAP(Dot Net And Prototype) awhile back and decided that it is a useful idea afterall. 

What is it?

It's the middleman I use to wire up my dot net code on the back end to my javascript on the front end.  That's pretty much it in a nutshell. 

Why?

I use AjaxPro on occassion, but I ran into a few problems with conflicts between prototype and the javascript that is rendered with AjaxPro.  I'm sure there are ways around them but sometimes I don't feel like dealing with debugging javascript conflicts.

I liked a couple of things I was experimenting with too, like rendering validation code in the javascript method bodies so the server request isn't made if any of the necessary data is invalid.

I also wanted to be able to swap out JSON serializers if I felt like it.  I used Jayrock which works well enough but who knows, maybe i'll need and/or want to use another one sometime.  The plan is to have it wired up for swapping out libraries via web config.

Example Usage

Basically I need to be able to write some C# code, and without doing anything except inherit from a base page that does the magic.  At it's simplist, you define a method that you need to access from the client side.  Adorn it with the DNAP.GenericAjaxMethod attribute and make sure your page inherits from AjaxBasePage and you're good to go, the plumbing to call your method through the prototype.js Ajax object is wired up for you.

So click here to see the code behind that needs to be accessed from the clientside.  It's got a SUPER complicated method.

Click here to view the sample page that uses the code.

This is still one of my favorite parts.  Let's say you've set up your codebehind and now you want to use it from the clientside.  What's the syntax? how do I use it? call the name of your page followed by ?json=howto and a test page is rendered that explains how to call whatever code you have set up in codebehind. 

Download 

Here is the code, DNAP.zip(133K).

 
Author: , 0000-00-00