saideepak I don't see a reason why this shouldn't work, but you might be better off setting a cookie in the page init script, see here, look for http.request.createCookie("name", "value"). The default usercache expiry time is much shorter (and harder to control because you need support for that) than with a cookie, plus you'll have to execute that logic constantly in the page init script, which you want to keep as "clean" as possible, e.g. you don't want to pack more logic than absolutely necessary in there (can make your page loads even slower than they already are out of the box).
Another option I tend to use for more "temporary" stuff are session attributes, you can set them in the page init as well and use them later on.