Reputation: 5905
I am trying to read a C# property in JavaScript (not using Ajax). In C#, I am setting property on page load. I tried to read this property like so:
<script type="text/javascript">
var ProductId =<%=this.ProductId %>>
alert(ProductId); // not successful alert showed undefiend
function GetValueNow()
{
alert(<%=this.ProductId%>); // calling this function was showing value
}
</script>
I tried to access this property in on page load (in the JavaScript of the .aspx
page) but was not successful. Later, I tried to do this in a JavaScript function, and that worked.
Why can't I read the variable before the body of GetValueNow()
?
Upvotes: 0
Views: 193
Reputation: 57167
Looks like it is just a typo.
var ProductId =<%=this.ProductId %>>
should be:
var ProductId =<%=this.ProductId %>;
Upvotes: 3
Reputation: 35409
You've got an extra >
sign:
From:
var ProductId =<%=this.ProductId %>>
To:
var ProductId = <%=this.ProductId %>;
Upvotes: 5