top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

+2 votes
47 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 Google+ Share Button LinkedIn Share Button Multiple Social 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...