There's a lot of ways to do this.
But I think the best way would be to write the database value into the script using the ASP
Response.Write()
method.
First you need to define a variable (or variables) that is either Protected or Public in your Page's Code-Behind. Then you need to fill this variable (or variables) with data retrieved from your database.
After you've done that, switch over to your ASP.NET Design-Code, go to the place where your JavaScript is defined call the
Response.Write(variableName)
method to write the value of the variable(s) into the page.
Recall that anything between
<% %>
is server-side code that is called in order to render something at a particular place in your web page.
So, if you have two Public variable called latitudeServerSideVariable and longitudeServerSideVariable in your Page's Code-Behind that you fill with data from your database (say on your Page Load event)...You would then put the following in your JavaScript method to write their values into the script:
-
function initialize()
-
{
-
var lat = <%Response.Write(latitudeServerSideVariable);%>
-
var long = <%Response.Write(longitudeServerSideVariable);%>
-
....
-
}
Another, shorthand way to call the Response.Write method is to use
<%=
. So another way to accomplish the same thing as my above posted code would be to have:
-
function initialize()
-
{
-
var lat = <%=latitudeServerSideVariable%>
-
var long = <%=longitudeServerSideVariable"%>
-
....
-
}
-Frinny