views:

19

answers:

2

I have a HyperlinkButton in my Silverlight project. Clicking the link will open the URL in a new page:

<HyperlinkButton x:Name="Button1" Content="Click" 
  TargetName="_blank" Click="Button1_Click" 
  NavigateUri="http://www.example.com" />

When I click the button, I want a (second) asynchronous request to be fired to a statistics server:

private void Button1_Click(object sender, RoutedEventArgs e)
{
   WebClient webClient = new WebClient();
   webClient.Headers["content-type"] = "application/x-www-form-urlencoded";
   webClient.Encoding = Encoding.UTF8;
   webClient.UploadStringAsync(destURI, "POST", "action=click" + 
       "&id=" + id);
}

However, if I check with FireBug, this request is never fired. How can I make this request work?

Note: I have already checked that the destination page can receive requests. The destination has a correct clientaccesspolicy.xml and crossdomain.xml.

A: 

NavigateUri seems to take precedence over firing the event handler for Click, so what you would need to do is remove the NavigateUri, and handle everything inside the Click event itself.

You can use the HtmlPage.Window.Navigate() function to spawn a new window by setting the target to _blank, much like you did in the XAML for HyperlinkButton.

rakuo15
I did this before. This seems to fire the popup blocker of Firefox. Using NavigateUri doesn't.Moreover, attaching the Visual Studio debugger tells me the click method is called, so I really don't know why I don't see the request.
Scharrels
A: 

Argh. The problem is with Firebug. The browser window loses focus and requests are no longer captured. Wireshark shows that the request fires correctly.

Scharrels