Question

This is a simple syntax question, but I haven't been able to find (or haven't known quite how to phrase the question in order to find) an answer.

I'm trying to pass a Javascript variable into a .NET script like so:

var name = '<%=GetName(' + String(pageid) + ') %>';

GetName is a server-side .NET function, obviously. I get an "Expression Expected" server error thrown when I attempt to use it in its present state.

What's the problem with my syntax? Thanks!

Was it helpful?

Solution

You cannot do that. By the time that JavaScript is executed, the .NET page has already been rendered and left the server. You have to figure out another way to do that (precompute the value, xhr...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top