How to consume an ASP.NET webpage in JavaScript?

Ever wondered how you can use your .net page to render output in javascript, something similar to Google Ads (Adsense)? What you want to do is have an ASP.NET page which does a bit of logic coded in C#VB.NET which other people can consume on their websites through a simple javascript call to your asp.net page. The solution is really easy – all you have to do is create your webpage as normal and stick your business logic inside it and then for the things your want to output, you use:

// BusinessLogicPage.aspx

string message = “This is the output from my ASP.NET page!”;

Response.Write(“document.write(‘” + message + “‘);”;

Response.End();

// ConsumerPage.html (it can be anything because we are going to consume it in javascript

<script src=”BusinessLogicPage.aspx” type=”text/javascript”></script>

Where you place the script tag, you will get the output from your BusinessLogicPage just like when you place Adsense codes on your pages, Google delivers ads to these pages.

comments powered by Disqus