Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Monday, February 11, 2008

Open a webpage on button click in asp.net using C#

Sometimes we need to open a web page using a button click event. This post contains a sample code that can be used in a button click event to show a page using Javascript Window.open method. This code snippet is just a small piece just to give you an idea for the startup stuff. I hope you can improve, and modify it according to your need to achieve your required goal.

Here is the sample code. You can put this code in the click event of a button etc.


string strpage = "Url of the page to be opened";
string url = "";
this.RegisterStartupScript("", url);

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.