jeudi 13 août 2015

Passing Class as an argument to an image click event Handler

I have a Trip object which I am getting from list TripsByTripIds which I want to pass as a parameter to image click event handler down below. how do I pass it?

  foreach (Tripclass Trip in TripsByTripIds )
  {
      ImageButton imageButton = new ImageButton();
      imageButton.ImageUrl = "~/" +Trip.CorridorName+"/"+Trip.Time+"/"+Trip.ImgFileName;
      imageButton.Height = Unit.Pixel(100);
      imageButton.Style.Add("padding", "5px");
      imageButton.Width = Unit.Pixel(100);
      imageButton.Click += new ImageClickEventHandler(imageButton_Click);
      AMSPanel1.Controls.Add(imageButton);
      AMSPanel1.Height = Unit.Pixel(860);
  }

  protected void imageButton_Click(object sender, ImageClickEventArgs fi)
  {
      testimage.ImageUrl = ((ImageButton)sender).ImageUrl;
      lblTime.Text = Trip.Time; 
      lblLocation.Text = Trip.Location; //can't access trip object here
  }    



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire