PC Review


Reply
Thread Tools Rate Thread

Control Array Problem

 
 
Toni
Guest
Posts: n/a
 
      25th Apr 2007
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>");
}


 
Reply With Quote
 
 
 
 
Alex Meleta
Guest
Posts: n/a
 
      25th Apr 2007
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 [private.php?do=newpm&u=]
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>");
}


 
Reply With Quote
 
Masudur
Guest
Posts: n/a
 
      26th Apr 2007
On Apr 25, 3:26 pm, "Toni" <n...@maila.hr> wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control Array Problem Toni Microsoft ASP .NET 1 26th Apr 2007 05:56 AM
Using control array run time with different control names AB Microsoft VB .NET 4 18th Jan 2006 02:22 PM
Re: Control array problem Robin Hammond Microsoft Excel Programming 1 31st Aug 2005 02:55 AM
Dynamic control array loading, can't unload control/replace with o =?Utf-8?B?Y2luZHk=?= Microsoft ASP .NET 2 8th Jun 2005 04:54 AM
Creating Server control's Control Array vivek Microsoft ASP .NET 2 30th Dec 2003 07:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 AM.