如何将包含vb net中的sql数据的变量传递给aspx中的javascript?
我知道有类似var y = <%=variable%>
的东西,但在我的例子中是y:variable。
分号阻碍我传递变量。
series: [{
name: 'Numbers',
colorByPoint: true,
data: [{
name: 'Server with IP Address',
y: 282
}, {
name: 'Server without IP Address',
y: 30
答案 0 :(得分:1)
有很多方法可以将这些值传递给javascript。以下是直接使用变量<%= variable %>
或使用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
}]
}];
背后的代码
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