Control Array Problem

T

Toni

I have ImageButton array. I have defined onClick event and it works. But in
this function I can not use control propetries. I want to use index of
ImageButton which is clicked and ImageURL property. How to use this?

protected void Page_Load(object sender, EventArgs e)
{
ImageButton[] HeaderImage = new ImageButton[6];

for (int n = 1; n < 6; n++)
{
HeaderImage[n] = new ImageButton();
HeaderImage[n].ImageUrl =
"Design/Templates/HeaderImage/HeaderImage"+n.ToString()+".jpg";
HeaderImage[n].Click += new
ImageClickEventHandler(HeaderImage_Click);

PanelPicture1.Controls.Add(HeaderImage[n]);
}
}

private void HeaderImage_Click(object sender, EventArgs e)
{
Response.Write(Convert.ToString(e) + "<br>");
Response.Write(Convert.ToString(sender) + "<br>");
}
 
M

Masudur

I have ImageButton array. I have defined onClick event and it works. But in
this function I can not use control propetries. I want to use index of
ImageButton which is clicked and ImageURL property. How to use this?

protected void Page_Load(object sender, EventArgs e)
{
ImageButton[] HeaderImage = new ImageButton[6];

for (int n = 1; n < 6; n++)
{
HeaderImage[n] = new ImageButton();
HeaderImage[n].ImageUrl =
"Design/Templates/HeaderImage/HeaderImage"+n.ToString()+".jpg";
HeaderImage[n].Click += new
ImageClickEventHandler(HeaderImage_Click);

PanelPicture1.Controls.Add(HeaderImage[n]);
}
}

private void HeaderImage_Click(object sender, EventArgs e)
{
Response.Write(Convert.ToString(e) + "<br>");
Response.Write(Convert.ToString(sender) + "<br>");
}

Hi.

Assign ID of the ImageButtons...
In Event handler cast the sender as image button and then check the
id...
then do what ever you like
Thanks
Masudur
 

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

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top