Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

HyperlinkButton doesn't fire click event in Beta2 RSS

9 replies

Last post Sep 24, 2008 07:47 PM by yaip

(0)
  • yaip

    yaip

    Member

    150 Points

    151 Posts

    HyperlinkButton doesn't fire click event in Beta2

    Sep 22, 2008 06:13 PM | LINK

    I've got following in my xaml file: The click event just won't fire. Is it a bug?
    Thanks
    I love computers because: MY WISH IS THEIR COMMAND :)

    <Website>
    <Gadget>
  • Harlequin

    Harlequin

    Member

    218 Points

    159 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 22, 2008 10:00 PM | LINK

    Did you post code? Sounded like you were posting some examples, but I don't see any.

  • yaip

    yaip

    Member

    150 Points

    151 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 22, 2008 10:27 PM | LINK

     aspx:

            <ItemsControl x:Name="itmStudents"  Margin="0,0,0,0" Canvas.Top="63.287" Canvas.Left="172.2" Padding="10"  >
                <ItemsControl.ItemTemplate >
                    <DataTemplate  >
                        <HyperlinkButton x:Name="hlbButton" FontSize="16"    Click="hlbButton_Click_3" ></HyperlinkButton>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

    vb:

        Private Sub asmx_GetStudentsWithAsmxCompleted(ByVal sender As Object, ByVal e As ServiceReference1.Get_StudentsCompletedEventArgs)
            Dim strStudent() As String = e.Result.Split("**")
            Select Case strStudent.Length

                Case Is > 20
                    txtMessage.Text = "More than 10 Students found. Please narrow you search."
                Case 1
                    txtMessage.Text = "No Students found."
                Case Else
                    txtMessage.Text = ""
                    For Each s As String In strStudent
                        If s <> "" Then
                            Dim linkButton As New HyperlinkButton
                            Dim strSingleStudent() As String = s.Split(",")
                            If s.Length > 1 Then
                                linkButton.Content = strSingleStudent(0) & " " & strSingleStudent(1)
                                linkButton.FontSize = 16
                                linkButton.Tag = strSingleStudent(2)
                            End If

                            Me.itmStudents.Items.Add(linkButton)
                        End If
                    Next
            End Select


            btnSubmit.Content = "Search"
        End Sub

    As you can see, I am building the link in my code-behind but the click event doesn't fire.

    This was working in Beta 1.

    Thanks
    I love computers because: MY WISH IS THEIR COMMAND :)

    <Website>
    <Gadget>
  • pbromberg

    pbromberg

    Contributor

    3138 Points

    531 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 22, 2008 11:54 PM | LINK

    I don't see in your code sample where you are wiring up the click event to each hyperlinkbutton.  From the docs:

     

    Dim handler As RoutedEventHandler

    AddHandler instance.Click, handler

    [C# MVP]
    Eggheadcafe.com
  • yaip

    yaip

    Member

    150 Points

    151 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 23, 2008 12:21 AM | LINK

     In my asmx file, when I add click event to hyperlinkbutton, it adds the following in my code-behind:

        Private Sub hlbButton_Click_3(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        End Sub

    But it never gets called when I click on the hyperlinkbutton.

    Thanks
    I love computers because: MY WISH IS THEIR COMMAND :)

    <Website>
    <Gadget>
  • yaip

    yaip

    Member

    150 Points

    151 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 23, 2008 12:23 AM | LINK

    pbromberg

    Dim handler As RoutedEventHandler

    AddHandler instance.Click, handler

     

    Do I have to add this manually in my code-behind? If yes, where?

    Thanks
    I love computers because: MY WISH IS THEIR COMMAND :)

    <Website>
    <Gadget>
  • Yi-Lun Luo - MSFT

    Yi-Lun Luo -...

    All-Star

    25149 Points

    2759 Posts

    Microsoft

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 24, 2008 07:37 AM | LINK

    Hello, you mentioned "In my asmx file, when I add click event to hyperlinkbutton, it adds the following in my code-behind". Are you sure you're adding an event handle in an asmx file? You should write this in XAML, for example, Page.xaml file:

    <HyperlinkButton Content="something" NavigateUri="http://somewebsite" Click="HyperlinkButton_Click"/>

     

    And then write this in code behind, for example, Page.xaml.vb file:

    Private Sub HyperlinkButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

    End Sub

     

    To test whether the event handler works, insert a break point. You can't say a HyperlinkButton's Click event handler doesn't work just because you invoke a web service in the event handler, waiting for a TextBlock's text to update based on the returned value of the web service, but the text never updated. The problem may well be the web service doesn't work probably.

    shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.
  • yaip

    yaip

    Member

    150 Points

    151 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 24, 2008 06:43 PM | LINK

     Yes, I am sure. I also put a break-point.

    This has been working in Beta 1.However, it stopped working in Beta 2.

    BTW, I don't use NavigateUri in my xaml as I am building the link in my code-behind.

     

    Thanks
    I love computers because: MY WISH IS THEIR COMMAND :)

    <Website>
    <Gadget>
  • sladapter

    sladapter

    All-Star

    43609 Points

    7910 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 24, 2008 07:17 PM | LINK

     Are you use Click event or MouseLeftButtonDown event? If you use the MouseLeftButtonDownEvent, change it to use Click event. That is the change in beta2.

    [Edit]

    Sorry, I read your code, you are using Click event. 

     

     

    Sally Xu
    Software Engineer
    Aprimo, Inc

    Please remember to mark the replies as answers if they answered your question
  • yaip

    yaip

    Member

    150 Points

    151 Posts

    Re: HyperlinkButton doesn't fire click event in Beta2

    Sep 24, 2008 07:47 PM | LINK

     I've tried both. No luck. Looks like a bug to me.

    Thanks
    I love computers because: MY WISH IS THEIR COMMAND :)

    <Website>
    <Gadget>