Question

Can I get print data in my .js files before sending them to the client? I want to be able to print the session id into a variable to use in getting around the flash cookie bug. Here's my code:

//Add our custom post-params
                var auth = "<% = If(Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing, String.Empty, Request.Cookies(FormsAuthentication.FormsCookieName).Value) %>";
                var ASPSESSID = "<%= Session.SessionID %>";

                this.setPostParams({
                    ASPSESSID: ASPSESSID,
                    AUTHID: auth
                });

That shows up exactly the same way in my js file. I want the server to process the code!

Was it helpful?

Solution

You can not include the .NET markup in the js file. You can use an ashx file to generate a dynamic script files if you really want to do it.

Why write it in the JS file? Write it to the page with ClientScriptManager.RegisterClientScriptBlock so the JavaScript can be cached properly. The script will still be able to access the variable in the page as long as the included script appears after the code.

OTHER TIPS

I think you want to use immediate if. Like:

var auth = "<% = iif(Request...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top