mhodder


Hi,

I have a VB.NET application with an embedded browser page with a Java script page to load the VE stuff.

Does anyone know if it is possible to send a message to the java script page to tell it to execute a particular function

It might be delete all push pins or add a pushpin for instance.

Thanks

martin





Re: Executing functions via VB .NET

Derek Chan


Depends on which framework your using.  But if your using 2.0 you can try using

Page.RegisterStartupScript()

More details on that here:
http://msdn2.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript.aspx

if its 1.1 I'd recommend using

Page.RegisterClientScriptBlock();

example:

Page.RegisterClientScriptBlock("YourKey","<script>alert('hi')</script>");

Details:
http://msdn2.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx







Re: Executing functions via VB .NET

SoulSolutions

eeek, only if you want to execute it only on page load or have post backs - VE does not like post backs.

Have a look at:

http://viavirtualearth.com/vve/Articles/Clustering.ashx

Ignore the clustering stuff and see how i control VE by sending javascript from vb.net using simple AJAX.

Send me an email if you want the complete source (it is a little old)

If you want to be really slick I suggest using the new ASP.NET AJAX to make webservices that pass data from vb.net to the client. That is very cool.

http://ajax.asp.net

John.







Re: Executing functions via VB .NET

mhodder

HI,

Thanks for your help.

I have finally managed to do this via the Invokescript() via a browser control.

this worked well excapt i have not managed to get paramters passed yet!

Regards

martin






Re: Executing functions via VB .NET

Anonymous

Private Sub btnGoTO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoTO.Click


If (Not (Browser.Document Is Nothing)) Then
Dim ObjArr(4) As Object
ObjArr(0) = CObj(Lat)
ObjArr(1) = CObj(Lng)
ObjArr(2) = CObj(Zoom_Level)
ObjArr(3) = CObj(New String(View_Type))
ObjArr(4) = CObj(Map_Movent)

Browser.Document.InvokeScript("SetLatLng", ObjArr)
' function SetLatLng(Lat,Lng,ZoomValue,ViewType,MapMovement)
Label1.Text = returnValue
End If
End Sub

Now On Your Java script


<script>

function SetLatLng(Lat,Lng,ZoomValue,ViewType,MapMovement)
{
try
{
map.SetMapMode(VEMapMode.Mode2D);
map.LoadMap(new VELatLong(Lat, Lng), ZoomValue ,ViewType ,MapMovement);


}
catch (err)
{
alert(err.message);
}
}
</script>




Re: Executing functions via VB .NET

Anonymous

Hi,

I have a similar situation, the script expects to recieve a form on the page to add parameters to, however having hard time passing the Form object. It fails in script saying: "Elements is null or not an object". Also it is every hard to debug this project to view the actual values passed to the script as the application includes the WebBrowser instance which VB debugger is already attached to. When the browser offers to debug, can't attach another debugger. Any suggestion is appreciated.

Dim objArray(3) As Object
Dim FormHTML As HtmlElement

If (WebBrowser.Document() Is Nothing) Then Return

FormHTML = WebBrowser.Document().GetElementById("Form1")

objArray(0) = CObj(FormHTML)
objArray(1) = CObj(Name)
objArray(2) = CObj(Value)
WebBrowser.Document.InvokeScript("addParamToForm", objArray)

Here is the script:

<script type="text/javascript" LANGUAGE="JavaScript">

function addParamToForm(ToFrom, sName, sValue) {
var objElement;
var i;

if(ToFrom) {
for (i=0; i < ToFrom.elements.length; i++) {
objElement = frmTo.elements;
if (objElement.name == sName) {
objElement.value = sValue;
break;
} //if
}//for

} //if

}

</script>