Global variables in one page are not kept by the next.
If you want this client-side, you have three options (at least):
Pass the variable to the next page on the query string, e.g.:
window.location = "WebForm2.aspx?myvar=" + encodeURIComponent(myvar);
Use a cookie (millions of examples online, I won't repeat them, bit of a pain to read the cookie).
Use client-side session storage or local storage, both of which are covered here. Here's the client-side session storage example:
// Setting
sessionStorage.myvar = myvar;
// Getting (on the next page)
var myvar = sessionStorage.myvar;
(sessionStorage
is a global variable provided by the browser.)
This works on just about any browser you need to care about (IE8+, and modern versions of basically everything else).
Server-side, both option 1 and 2 would work, but 1 would make the most sense.