allison_h


Hi,

I have a button in my html page (which is housed in a webBrowser control on a form) to save the lat and long of a pin.

when this button is clicked i want to pass these values back to the form to be saved.

i would also like to be able to run c# subroutines from the click of a html button.

how could i do this

Thanks,

ali.




Re: Fire C# routine on html button click


Re: Fire C# routine on html button click

Derek Chan

Allison,

If your using the 2.0 framework you can convert the HTML button into a server control and then handle the click event in your code behind.

There's a tutorial on how to do that here:
http://msdn2.microsoft.com/en-us/library/aa728785(vs.71).aspx

Regards,





Re: Fire C# routine on html button click

Duncan Garratt

Here is an example of calling an external JavaScript function that will pass JavaScript variables from a web browser embeded in a winform to the winform or class

using System.Security.Permissions;

//Add to namespace

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]

[System.Runtime.InteropServices.ComVisibleAttribute(true)]

//JavaScript

function YourJavaScriptFunction()

{

// do something here in JavaScript to get the variable values

// Passing variables back to the winform

window.external.GetPanEndExternal(LatNorth,LatSouth,LongEast,LongWest,mapStyle,zoomLevel);

}

//C# method to receive the the variables

public void GetPanEndExternal(double LatNorth, double LatSouth, double LongEast, double LongWest, string mapStyle, int zoomLevel)

{

//do something here with the variables

// Such as firing a custom event etc

}

Here is C# code to invoke a script within the embeded web browser

// PanTo is the JavaScript funcation to execute

VEBrowser.Document.InvokeScript("PanTo", new string[] { Latitude.ToString(), Longitude.ToString() });

Duncan Garratt

http://www.gis-logic.co.uk/