top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

WindowsPhone:How to detect which button was clicked in code behind c#?

+2 votes
404 views
WindowsPhone:How to detect which button was clicked in code behind c#?
posted Jun 22, 2015 by Puhal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

This is the sceneria where multiple buttons having same click event,and so we need to find which button is clicked on code behind when "Click" is fired.For example here i taken 3 buttons b1,b2,b3 with same click event is "GetName_Click".

Xaml:

<Button Name="b1" Click="GetName_Click"/>
<Button Name="b2" Click="GetName_Click"/>
<Button Name="b3" Click="GetName_Click"/>

C#:

private void GetName_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            if(btn.Name=="b1")
            {
                //selected button name is 'b1'
            }
            if (btn.Name == "b2")
            {
                //selected button name is 'b2'
            }
            if (btn.Name == "b3")
            {
                //selected button name is 'b3'
            }
        }
answer Jun 23, 2015 by Jdk
...