tags:

views:

26

answers:

1

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();
}
A: 

Could you try putting some javascript in the onsubmit that return falses it?

Evernoob
Yes, certainly javascript would work, I guess I was trying to do it entirely in silverlight.
INinjaAndy