1

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
asked Dec 19, 2016 at 7:18
2
  • This is usually done via a restful service with AJAX. Commented 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... Commented Dec 19, 2016 at 7:56

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.