473,468 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Control Array Problem

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>");
}
Apr 25 '07 #1
2 2220
You can access the control using casting sender parameter to the called
control type:

ImageButton imageButton = (ImageButton) sender;

Regards, Alex Meleta
Blog:: http://devkids.blogspot.com

-----Original Message-----
From: Toni [mailto:ne**@maila.hr]
Posted At: Wednesday, April 25, 2007 1:26 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: Control Array Problem
Subject: Control Array Problem

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>");
}
Apr 25 '07 #2
On Apr 25, 3:26 pm, "Toni" <n...@maila.hrwrote:
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

Apr 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christopher | last post by:
Hi I need to know how to work with a control array in c#. I would like to clear the contents of a textbox array after adding up the values in the textboxes. This is really easy in VB6 - im sure...
4
by: bienwell | last post by:
Hi all, Data displayed on the datalist control is bound by the column name of the dataset like this : <%# DataBinder.Eval(Container.DataItem, "title")%> Could I use an element of the array...
2
by: Allan Bredahl | last post by:
Hi all Im currently constructing a Windows control that inherits from RichTextBox, but I'm having a bit of trouble with updating the control at design time. The senario is SIMPLIFIED as...
0
by: Allan Bredahl | last post by:
Hi all Im currently constructing a Windows control that inherits from RichTextBox, but I'm having a bit of trouble with updating the control at design time. The senario is SIMPLIFIED as...
0
by: Allan Bredahl | last post by:
Hi all Im currently constructing a Windows control that inherits from RichTextBox, but I'm having a bit of trouble with updating the control at design time. The senario is SIMPLIFIED as...
6
by: Rich | last post by:
Hello, I have an application that contains several checkboxes. I originally created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I understand the vb2005 supports control...
3
by: mabond | last post by:
Hi all I have an rtf control on my form. The control is populated with text from an string array created as the application runs. The code to populate the rtf control is as follows For l = 0...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
5
by: Sedecrem | last post by:
I am creating a 'frogger' like game. Essentially there are ten lanes each with an image array associated with it. The arrays are named from imglane0() to imglane9(). I was creating a piece of code...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.