Reputation: 2169
<script type="text/javascript">
/* <![CDATA[ */
var on_id = 1;
if (<%=GetValue() %>) {
on_id = <%=GetValue() %>;
}
</script>
I do get 2 syntax errors: at the 2nd closed brachet: after %>
and at ;
after again %>
. GetValue()
is a public decimal method defined in code behind.
How can I achieve this?
Upvotes: 1
Views: 172
Reputation: 434
Try this
<script type="text/javascript">
var on_id = 1;
<%if (GetValue()) {%>
on_id = '<%=GetValue() %>';
<%}%>
</script>
Upvotes: 0
Reputation: 2869
im not an expert but i had faced a similar problem.it got solved by putting <%=GetValue() %> in ''(single quotes) i.e '<%=GetValue() %>' so i stopped getting syntax errors
use parseFloat() function to get the float value from the string
Upvotes: 1
Reputation: 769
$.ajax({
type: "POST",
url: 'yoururl/GetValue',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunction,
error: errorFunction
});
Do it using an AJAX call :)Check the condition in successhandler
Upvotes: 0