function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(-30,90), 1);
var point = new GLatLng(-30,90);
I see nothing really wrong with the JavaScript. Add this to your Page_Load event handler and see if that is what you want
vbnetbutton.Attributes.Add("onclick", "load();")
still not working. The output is http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA
a string.
can you please check my code . and if possible modify it
Thanks a lot for prompt reply.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Button1.Attributes.Add("onclick", "load();")
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim strscript As String
strscript = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA"
strscript += "<script src=" & """" & strscript & """"
strscript += " type=text/javascript></script>"
strscript += "<script type=text/javascript > "
strscript += "function load() {"
strscript += " if (GBrowserIsCompatible()) {"
strscript += " var map = new GMap2(document.getElementById(map));"
strscript += " map.setCenter(new GLatLng(-30,90), 1);"
strscript += "var point = new GLatLng(-30,90);"
I don't know what else to tell you. Maybe if you'd explain more concisely what you are trying to do, we could help.
Can we access vb.net variable in javascript.?
In the aspx.vb file:
Public Property YourProperty() As String
Get
Dim viewState As Object = Me.ViewState("YourProperty")
If viewState Is Nothing Then
Return String.Empty
Else
Return CStr(viewState)
End If
End Get
Set
Me.ViewState("YourProperty") = value
End Set
End Property
Thanks sir for the variable code. Sir i'll explain what i'm trying to do.
In the code posted on my first post, the script displays a google map for given the latitude longitude of a point. You can copy paste the code below in notepad and save it as test.html. Open it with IE or firefox. Now you can see the google map. ( And
if you can't see it create a virtual directory called jscript and put this test.html there ,you can display the google map by navigating to http://localhost/jscript/test.html )
Now i want to display the same behavior when i press a button on my asp.net web form so that i can pass longitude and latitude at runtime.and google map is displayed for that point.
Test.html code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(-30,90), 1);
var point = new GLatLng(-30,90);
NileshBEIT
Member
1 Points
9 Posts
calling given javascript script from vb.net button click
Mar 04, 2008 09:25 AM|LINK
Respected members
Can anybody please help me to call the script given below after vb.net button click
The script below displays google map on normal html page.
when i tried using ClientScript.RegisterStartupScript , iam getting error on line 7 missing ; error
If you can provide the modified code i'll be grateful to u.
Thanks in advance
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xQpTR6YCxnSXrgb0dAWLhf5sIEOjRResgehB9eed2b9p_qltU3hRBfG4g"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(-30,90), 1);
var point = new GLatLng(-30,90);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 1024px; height: 840px"></div>
</body>
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: calling given javascript script from vb.net button click
Mar 04, 2008 06:42 PM|LINK
I see nothing really wrong with the JavaScript. Add this to your Page_Load event handler and see if that is what you want
vbnetbutton.Attributes.Add("onclick", "load();")
Replace "vbnetbutton" with the actual button.
NC...
NileshBEIT
Member
1 Points
9 Posts
Re: calling given javascript script from vb.net button click
Mar 06, 2008 02:04 PM|LINK
Dear NC
still not working. The output is http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA
a string.
can you please check my code . and if possible modify it
Thanks a lot for prompt reply.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadButton1.Attributes.Add("onclick", "load();")
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim strscript As String
strscript = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA"
strscript += "<script src=" & """" & strscript & """"
strscript += " type=text/javascript></script>"
strscript += "<script type=text/javascript > "
strscript += "function load() {"
strscript += " if (GBrowserIsCompatible()) {"
strscript += " var map = new GMap2(document.getElementById(map));"
strscript += " map.setCenter(new GLatLng(-30,90), 1);"
strscript += "var point = new GLatLng(-30,90);"
strscript += "var marker = new GMarker(point);"
strscript += "map.addOverlay(marker);"
strscript += " }"
strscript += " }"
strscript += " </script>"
strscript += " </head>"
strscript += "<body onload=load()onunload=GUnload()>" '
strscript += " <div id=map style=width: 1024px; height: 840px></div>"
strscript += "</body>"
Page.RegisterStartupScript("SetFocusScript", strscript)
End Sub
aspdotnetjun...
Participant
796 Points
220 Posts
Re: calling given javascript script from vb.net button click
Mar 06, 2008 03:53 PM|LINK
Check you js, why is there a closing </head> html tag.
You can't add this "<body onload=load()..." but you can do something like document.getElementById('bodyID').function () { .....}
Life's good
My Site
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: calling given javascript script from vb.net button click
Mar 06, 2008 04:30 PM|LINK
Try this:
Dim strscript As String
strscript = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA"
strscript += "<script src=" & """" & strscript & """"
strscript += " type=text/javascript></script>"
strscript += "<script type=text/javascript > "
strscript += "function load() {"
strscript += " if (GBrowserIsCompatible()) {"
strscript += " var map = new GMap2(document.getElementById(map));"
strscript += " map.setCenter(new GLatLng(-30,90), 1);"
strscript += "var point = new GLatLng(-30,90);"
strscript += "var marker = new GMarker(point);"
strscript += "map.addOverlay(marker);"
strscript += " }"
strscript += " }"
strscript += "window.onload=load; window.onunload=GUnload();"
strscript += "</script>"
Page.RegisterStartupScript("SetFocusScript", strscript)
NC...
NileshBEIT
Member
1 Points
9 Posts
Re: calling given javascript script from vb.net button click
Mar 06, 2008 05:54 PM|LINK
Dear NC
The output is still http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA
a string
The map is still not displayed. But firefox do visits maps.google.com web( i can see in status bar) but doesn't display anything.
IE 7 ERROR :
Line:38
Char:22
Code:0
Error:Object required
URL:http://localhost/jscript/Default.aspx
Nilesh
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: calling given javascript script from vb.net button click
Mar 06, 2008 06:11 PM|LINK
Change these 3 lines as follows:
Dim strscript As String
Dim mapUrl As String = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA"
strscript = "<script src=" & """" & mapUrl & """"
The rest goes here
NC...
NileshBEIT
Member
1 Points
9 Posts
Re: calling given javascript script from vb.net button click
Mar 07, 2008 06:16 AM|LINK
Dear NC
Output is still string in mapurl
The firefox visits maps.google.com but doesn't disply it.
Meanwhile i tried to put code in design source, all that <>..... source window.
There while loading form the map is displayed below button.
Can we access vb.net variable in javascript.? how if yes?
Even that will do
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: calling given javascript script from vb.net button click
Mar 07, 2008 11:19 AM|LINK
I don't know what else to tell you. Maybe if you'd explain more concisely what you are trying to do, we could help.
Can we access vb.net variable in javascript.?
In the aspx.vb file:
Public Property YourProperty() As String
Get
Dim viewState As Object = Me.ViewState("YourProperty")
If viewState Is Nothing Then
Return String.Empty
Else
Return CStr(viewState)
End If
End Get
Set
Me.ViewState("YourProperty") = value
End Set
End Property
In the aspx file:
<script type="text/JavaScript">
<!--
var yourProperty = '<%= YourProperty %>';
// -->
</script>
NC...
NileshBEIT
Member
1 Points
9 Posts
Re: calling given javascript script from vb.net button click
Mar 07, 2008 04:47 PM|LINK
Thanks sir for the variable code. Sir i'll explain what i'm trying to do.
In the code posted on my first post, the script displays a google map for given the latitude longitude of a point. You can copy paste the code below in notepad and save it as test.html. Open it with IE or firefox. Now you can see the google map. ( And if you can't see it create a virtual directory called jscript and put this test.html there ,you can display the google map by navigating to http://localhost/jscript/test.html )
Now i want to display the same behavior when i press a button on my asp.net web form so that i can pass longitude and latitude at runtime.and google map is displayed for that point.
Test.html code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAGmS6k6UngyTjN0Lp26Kk5xToVEdh03njOGkWtau-MUzyoLPdjRSUI1wdptpaZY9hrefPNJaRbyKwmA"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(-30,90), 1);
var point = new GLatLng(-30,90);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 500px; height: 300px"></div>
</body>
</html>
Produces the output