PGP_Protector
PGP_Protector

Reputation: 228

JavaScript Syntax Error with ASP.NET Variable

I have a JavaScript Variable that is set in my ASP.NET page as follows

<script type="text/javascript>
var MyVarable = <%=ASPNETVarable%>;
$(document).ready(function () {
  alert(MyVarable);
}
</script>

Now this is simplified and on the back end code ASPNETVarable is set as

protected string ASPNETVarable="My Backend Value";

The page loads & runs correctly, but in Visual Studio the line

 var MyVarable = <%=ASPNETVarable%>;

Shows that it's a "Syntax error", while it works, how do I remove this "syntax error" ?

Upvotes: 1

Views: 1051

Answers (1)

TGH
TGH

Reputation: 39248

Try the following

var MyVarable = '<%=ASPNETVarable%>';

Upvotes: 2

Related Questions