Imagebutton click event

G

Guest

Hello,

I have a loop e.g.
for(i=0;i<10;i++)
{
ib = new ImageButton();
}

and all i want is to know which imagebutton the user clicked and populate a
textbox
how could i do that?

thanks in advance,
akis
 
G

Guest

1- because you are adding those imagebuttons dynamically, you have to add
them in the OnInit event handling
2- wire up the Command event to a common eventhandler for all buttons
ImageButton ib;
for(int i=0;i<10;i++)
{
ib = new ImageButton();
ib.CommandName ="Command"+i;
ib.Command +=new CommandEventHandler(btnImage_Command);
//ib.ImageUrl ="SOMIMAGE.JPG";
plholder1.Controls.Add (ib);
}
3- identify which button was pressed by examining the CommandName property
of the CommandEventArgs parameter

private void btnImage_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName )
{
case "Command1":
//process this command
break;
case "Command2":
//process this command
break;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top