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!

有帮助吗?

解决方案

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...)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top