How do i pass a variable that contain data from sql in vb net to javascript in aspx?
I know there's something like var y = <%=variable%>
but in my case is y: variable.
The semicolon is obstructing me from passing a variable.
series: [{
name: 'Numbers',
colorByPoint: true,
data: [{
name: 'Server with IP Address',
y: 282
}, {
name: 'Server without IP Address',
y: 30
VDWWD
35.7k23 gold badges67 silver badges87 bronze badges
-
This is usually done via a restful service with AJAX.IronAces– IronAces2016年12月19日 07:42:23 +00:00Commented Dec 19, 2016 at 7:42
-
P.S You're going to have to provide more code. An object literal alone does not help us to help you...IronAces– IronAces2016年12月19日 07:56:53 +00:00Commented Dec 19, 2016 at 7:56
1 Answer 1
There are a lot of ways to get those values to javascript. Here are 2 examples using a variable directly <%= variable %>
or with a Literal Control
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
var withOutIP = '<%= myVariable1 %>';
series: [{
name: '<%= myVariable2 %>',
colorByPoint: true,
data: [{
name: withIPfromCB,
y: 282
}, {
name: withOutIP,
y: 30
}]
}];
Code behind
Dim myVariable1 As String = "myVariable1"
Dim myVariable2 As String = "myVariable2"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Literal1.Text = "var withIPfromCB = 'Text';"
End Sub
answered Dec 19, 2016 at 8:17
Comments
default