الشبكة العربية لمطوري الألعاب

مبتدئ  إياد طرابلسي مشاركة 1

Why many of ImageButton webcontrol are protected!!? like .OnClick and how could we reach them when we add ImageButton automatically??

I need to click on the automatically added icon, so it sends the event to it's function, but I couldn't make it because you cannot reach .OnClick event, it's protected!!

Here is the code


ImageButton[] imageBtt = new ImageButton[images.Length];
foreach (string image in images)
{

imageBtt[i] = new ImageButton();
imageBtt[i].ID = "imageBtt" + i;
imageBtt[i].Visible = true;

imageBtt[i].OnClick = "ImageButton_Click";
imageBtt[i].ImageUrl = image;

ContentPlaceHolder3.Controls.Add(imageBtt[i]);
i++;
}


I receives this error:

Line 80: imageBtt[i].OnClick = "ImageButton_Click";

Compiler Error Message: CS0122: 'System.Web.UI.WebControls.ImageButton.OnClick(Sys tem.Web.UI.ImageClickEventArgs)' is inaccessible due to its protection level

محترف مشرف عبد اللطيف حاجي علي مشاركة 2

Use:
imageBtt[i].Click += new System.EventHandler(ImageButton_Click);

OnClick property is only intended to be used inside the HTML design stage...

عبد اللطيف حاجي علي
مبرمج
In|Framez

مبتدئ  إياد طرابلسي مشاركة 3

Thank you very much, I got it now..
I like the one statement professional reply
I made it like this..




imageBtt[i].Click += new System.Web.UI.ImageClickEventHandler(ImageButton_Click);