1

I am making a user control that displays imagebuttons. I am fetching the id, imageURL and image onclick event handler name from an xml file. But the event handler name is not being accepted. My code in .ascx.cs is:

var imageDetails = from image in imageDetailsXML.Descendants("image")
                       select new
                       {
                           imgID = image.Element("imgID").Value,
                           imgUrl = image.Element("imgUrl").Value,
                           imgClickHandler = image.Element("imgClickHandler").Value
                       };
    foreach (var imageBtn in imageDetails)
    {
        ImageButton imgBtn = new ImageButton();
        imgBtn.ID = imageBtn.imgID.ToString();
        imgBtn.ImageUrl = imageBtn.imgUrl.ToString();
        imgBtn.Height = height;
        imgBtn.Width = width;
        imgBtn.Visible = false;
        imgBtn.Click += new ImageClickEventHandler(imageBtn.imgClickHandler); 
        Panel1.Controls.Add(imgBtn);
     }

The imgClickHandler is implemented in the .aspx.cs page. How to bind the image click event of image button inside user control to the handler in the .aspx.cs page? I went to the following link : How to work with delegates and event handler for user control ,but could not understand the solution. Please help.

Community
  • 1
  • 1
Abhay Kumar
  • 833
  • 3
  • 11
  • 24

0 Answers0