Tutorial: Opening a Pop-up window in ASP.net

There are many reasons that a user would want to open up a new window from your ASP site. Maybe the clicked on a button or a link, maybe the current page just isn’t doing if for them.  Maybe their current page has self-esteem

issues, or weight issues.  Maybe their current page is getting a little thin on top, or doesn’t really do to well in the bedroom.

Back to maybe they clicked on a button.

Opening a new window from current page is actually quite simple! and can be accomplished in three steps:

  1. Create a control on the page that can handle and “onClick” event. This could be a plain HTML button, an anchor tag, an image, whatever…
  2. Double clicking on the control will open the code for the new HTML control. It should look like this:

function Button1_onclick() { }

[pullquote]

Look what I made at School!!
[/pullquote]

Remember, for this to work you’ve got to use a plain HTML control, not a “runat=server” .net control. These are found in the HTML Tab on the left.

And finally, the code that goes inside is:

The parameters are (the url of the new window, the title of the new page, size stuff)

View the page, click on the button/link/whatever and Whala! a new window opens.

Tutorial: Pass data between pages in ASP.net

You have created the perfect webpage. Beautifully formed HTML, poetic CSS, artistic JavaScript, and cunning jQuery. And suddenly — a link — and all user data is lost!

By far, the simplest way to pass data between pages is by using URL variables. These little nuggets act quite a bit like two pages playing catch:

  • the first page throws some variables along with the URL
  • the second page must catch them

the throw

Get the data, save it as a string like this:

then send the data to a page like this

Thats it!

And now for a little explanation of part one:

the “?” after the url means “hey server, get ready… Im about to pass you some data.”

“name=” this is what im going to be passing you.

and “strName”… Here’s the data!

It’s pretty simple to pass multiple values too: just put an & symbol between variables, like this:

Be sure to put this inside of some sort of event in the code behind, like a button or linkbutton click.

the catch

This part is almost as simple to implement as the throw. The basic steps are:

  • get the variable from the url, if it is there
  • the store it, or use it right then

As your page is loading, your want to let the server know that you are expecting some data, and store it if there.

this is done by using:

Then you are free to do any ifs, fors, dos, or other whathaveyous on your string that you would like.

For example: Im expecting a username, but since i didn’t get one, send them back home: