Friday, February 23, 2007

Server Side Variables in an Alert in ASP

If you need to see the value of a server side variable in ASP you can insert a script tag an inside the script tag you can put a server side variable of function call. It seems a little odd at first and if you are using the Visual Studio IDE the color coding even makes you think you are doing something wrong, but it seems to work.

Here's the situation. You have loaded something into a server side variable and you want to find out what that value is.

Note the single quotes around the server tags. Without the single quotes, the JavaScript evaluates the contents of the variable as code and not a string. Also note the = in front of the server side variable. This causes it to return the value of the variable.

In the image I attached I failed to insert the attributes for the script tag, so be sure you do that to tell it that it is JavaScript.