Hi all i am having 2 imagebuttons a gridview and a button. Now if i clicked on Image button i will show a grid. Now under button click i would like to capture which image button was clicked if 1st image button is clicked i would like to some values and if 2nd one is clicked i would like to show another
2 Answers
Can't you create 2 events and one function? ex:
//Hook both OnClick events to these!
private void OnButton1Click(object sender, EventArgs e) { BeenClicked(button1); }
private void OnButton2Click(object sender, EventArgs e) { BeenClicked(button2); }
private void BeenClicked(Button ClickedButton)
{
if(ClickedButton.Text == Button1) Console.WriteLine("Hi to you too!");
}
Or alternatively you could use:
//Hook both OnClick events to this!
private void OnButtonClick(object sender, EventArgs e)
{
ClickedButton = (Button)sender;
if(ClickedButton.Text == Button1) Console.WriteLine("Hi to you too!");
}
If I understood you right :)
4 Comments
Developer
But for Imagebutton text option is not available
Developer
Some what ok but i am unable to handle this in button click
Timwi
Why the comparison with
.Text? Just compare the button itself: if (sender == MyButton1) ...Blam
Sorry had a complete mind lapse, I up voted yours to thank you for pointing out my retarded ways :)