email hyperlinkbutton
Asked Answered
E

2

6

I'm trying to use a hyperlink button as a mailto in silverlight 4 like so:

<HyperlinkButton x:Name="hlbCustomerSupport" NavigateUri="mailto:[email protected]" Content="[email protected]"></HyperlinkButton>

and when I click it in the application I get:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E) Timestamp: Wed, 19 Jan 2011 14:24:29 UTC

Message: Unhandled Error in Silverlight Application Code: 4004
Category: ManagedRuntimeError
Message: System.ArgumentException: Content for the URI cannot be loaded. The URI may be invalid. Parameter name: uri at System.Windows.Navigation.NavigationService.NavigateCore(Uri uri, NavigationMode mode, Boolean suppressJournalAdd, Boolean isRedirect) at System.Windows.Controls.Frame.Navigate(Uri source) at MS.Internal.NavigationHelper.TryInternalNavigate() at MS.Internal.NavigationHelper.Navigate(Boolean checkUserInitiatedAction) at System.Windows.Controls.HyperlinkButton.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

I do this programatically elsewhere and it works. I tried the same approach for this one and still get the error.

Estuary answered 19/1, 2011 at 14:27 Comment(0)
E
8

I figured it out. The hyperlinkButton that works is in a child window (far nested control), the one that doesn't is in the site template (Child of the Application object). For this reason it appears that the hyperlinkbutton in the site template must have TargetName="_blank" specified. Not sure why this is.

Estuary answered 19/1, 2011 at 16:19 Comment(0)
B
0

I was able to work around the error by adding a click event to the xaml and storing the url in the Tag="" property.

XAML:

<HyperlinkButton Content="PDR Drug Handbook" Tag="http://www.pdrhealth.com/" FontSize="14" Click="HyperlinkButton_Click" />

Code Behind:

private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
    {
        HyperlinkButton button = (HyperlinkButton)sender;
        System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(button.Tag.ToString()), "_self");
    }

EDIT: popup blockers are now less likely to be invoked due to changing the target from "_blank" to "_self"

Benia answered 7/2, 2012 at 22:52 Comment(2)
From what I have seen any method other than via the NavigateUri seems to be blocked by pop up blockers. If you are looking at multi browser support this is not an option.Mordancy
That's a good point, I didn't think about popup blockers. I changed the hyperlink target to "_self" with popup blockers in mind. As the target doesn't matter for a mailto:Benia

© 2022 - 2024 — McMap. All rights reserved.