WEB.CONFIG
<?xml version="1.0"?>
<configuration>
<appSettings>
<!--
DECLARE VARIABLES HERE THAT WE WANT TO SHARE BETWEEN THE CLIENT AND THE SERVER. PREFIX WITH "tojs_".
-->
<add key="tojs_currentStep" value="7"/>
</appSettings>
<configuration>
|
PAGE.ASPX
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<%Response.Write(syncrhonizeJSParametersWithWebConfig())%>
</head>
<body>
...
</body>
</html>
|
CODE-BEHIND (PAGE.ASPX.VB)
Imports System.Configuration.ConfigurationManager
Public Function syncrhonizeJSParametersWithWebConfig() As String
Dim jsConfigure As String = "<script language=""text/javascript"" type=""text/javascript"">" & vbCrLf & "<!--" & vbCrLf & "/* Written by: Joe McCormack. This Javascript Block Genereated by the .Net Custom Function syncrhonizeJSParametersWithWebConfig() */" & vbCrLf
Dim key As String = String.Empty, keyName As String = String.Empty, keyValue As String = String.Empty
For Each key In AppSettings.AllKeys
keyName = key : keyValue = System.Configuration.ConfigurationManager.AppSettings(key)
If InStr(LCase(keyName), "tojs_") - 1 > -1 Then
If IsNumeric(keyValue) Then
jsConfigure = jsConfigure & "var " & Replace(keyName, "tojs_", "") & " = " & keyValue & ";" & vbCrLf
Else
keyValue = Replace(keyValue, "<", "<")
keyValue = Replace(keyValue, ">", ">")
keyValue = Replace(keyValue, """, """")
jsConfigure = jsConfigure & "var " & Replace(keyName, "tojs_", "") & " = " & """" & keyValue & """;" & vbCrLf
End If
End If
Next key
jsConfigure = jsConfigure & "//-->" & vbCrLf & "</script>" & vbCrLf
Return jsConfigure
End Function
|
|