I'm having problems with this source code.

I am loading a image from a SQL server. When the image is loaded, the window (opener window -> little) should be the size of the image. I want to trigger a javascript script after the asp.Net code. How do I do this:

Code:
If type = 1 then
	image1.imageUrl = lookforimage(imageNr)

	I WANT TO TRIGGER THE JAVASCRIPT HERE ? BUT HOW?