473,722 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ 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(objec t 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()+".jp g";
HeaderImage[n].Click += new
ImageClickEvent Handler(HeaderI mage_Click);

PanelPicture1.C ontrols.Add(Hea derImage[n]);
}
}

private void HeaderImage_Cli ck(object sender, EventArgs e)
{
Response.Write( Convert.ToStrin g(e) + "<br>");
Response.Write( Convert.ToStrin g(sender) + "<br>");
}
Apr 25 '07 #1
2 2235
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**@mai la.hr]
Posted At: Wednesday, April 25, 2007 1:26 PM
Posted To: microsoft.publi c.dotnet.langua ges.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(objec t 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()+".jp g";
HeaderImage[n].Click += new
ImageClickEvent Handler(HeaderI mage_Click);

PanelPicture1.C ontrols.Add(Hea derImage[n]);
}
}

private void HeaderImage_Cli ck(object sender, EventArgs e)
{
Response.Write( Convert.ToStrin g(e) + "<br>");
Response.Write( Convert.ToStrin g(sender) + "<br>");
}
Apr 25 '07 #2
On Apr 25, 3:26 pm, "Toni" <n...@maila.hrw rote:
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(objec t 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()+".jp g";
HeaderImage[n].Click += new
ImageClickEvent Handler(HeaderI mage_Click);

PanelPicture1.C ontrols.Add(Hea derImage[n]);
}
}

private void HeaderImage_Cli ck(object sender, EventArgs e)
{
Response.Write( Convert.ToStrin g(e) + "<br>");
Response.Write( Convert.ToStrin g(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
6404
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 it easy in C# aswell - i just need the syntax. Thanks in anticipation Christopher
4
2217
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 (i.e. index=0) which has the name "title" in place of it ? For example:
2
1245
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 follows: My RichTextBox control : Public Class Crtb
0
1031
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 follows: My RichTextBox control : Public Class Crtb
0
1086
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 follows: My RichTextBox control : Public Class Crtb
6
3059
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 arrays. Is this correct? If so, I would like to convert my checkboxes to a control array, but without having to recreate them from scratch because their placement was a real pain. Is it possible to go to the property sheet of each checkbox and assign...
3
3621
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 To arrayList.GetUpperBound(0) If arrayList(l, 0) Is Nothing Then 'do nothing Else
0
5292
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 the days in the week with dates and textboxes to fill in some data. row 1: question
5
1750
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 that moved the img boxes in the array by random amounts whilst checking for collisions etc. and it worked, for one lane. I designed a module that would theoretically allow the movement of every lane without having to constantly repeat lines of code....
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9088
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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 we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.