I have a Silverlight control that uses HtmlElement.AttachEvent() to execute code on form submit but I can't seem to be able to cancel the event and prevent the browser from actually posting the page. My guess is that HtmlEventArgs.PreventDefault() is what I need but this doesn't seem to work, any ideas?
public MainPage()
{
InitializeComponent();
var form = (HtmlElement)HtmlPage.Document.GetElementsByTagName("form").FirstOrDefault();
if (form != null)
{
form.AttachEvent("onsubmit", (EventHandler<HtmlEventArgs>)onSubmit);
}
}
private void onSubmit(object sender, HtmlEventArgs e)
{
// do something
e.PreventDefault();
}