Sunday, January 20, 2008

Accessing aspx page in javascript code using src attribute

Sometimes .net web developers need to access an asp.net web page in the javascript. A scenario where this kind of feature can be very helpful is one when you want to make some kind of processing using aspx page at your website or web server and then you want to show the output of this processing on some other website which can be static HTML site or using some other server side processing language i.e. PHP or JSP etc.

To achieve this functionality add an aspx page in your .net web application. Remove all the code from the aspx source file except the page directive at the top.

Now there are two ways to through output from this page to other file. Either you can write the contents using document.write method in the aspx source file or using document.write in the Response.write inside code behind file.

First Response.Write and then document.write enclosed in Response.write.

To access this page from other website or page just add the script tag in the html code of the page and specify language as javascript and the page as src of the script tag.

No comments: