asp.net variable in javascript

  • Thread starter Thread starter Nikhil Patel
  • Start date Start date
N

Nikhil Patel

Hi all,
I want to access a asp.net variable from Javascript. I tried the
following line in Javascript but it did not work. sAccountNo is the ASP.Net
variable I need to access and store its value in a Javascript variable.
var AccountNo = "<%= sAccountNo %>";
I also tried the following line but no success...
var AccountNo = <%= sAccountNo %>;
Thanks...
-Nikhil
 
What did the generated HTML look like? Did you receive any error?

Matt Hawley, MCAD .NET
http://www.eworldui.net



Hi all,
I want to access a asp.net variable from Javascript. I tried the
following line in Javascript but it did not work. sAccountNo is the ASP.Net
variable I need to access and store its value in a Javascript variable.
var AccountNo = "<%= sAccountNo %>";
I also tried the following line but no success...
var AccountNo = <%= sAccountNo %>;
Thanks...
-Nikhil



[microsoft.public.dotnet.framework.aspnet]
 
Hi, Nikhil Patel,

The server-side tags (<% %>) are not considered if they are within
<script></script> block. Try to generate the complete script on the server
and then add it to the html of the page with the RegisterClientScriptBlock
method on the Page instance.

Hope this helps
Martin
 
maybe asp.net codebehind variable is private, thus it cannot be accessed
from protected auto-generated _aspx class ...
 
Thanks all.
I tried following and it worked for me.

var AccountNo = "<%# sAccountNo %>";
 
Back
Top