Dynamic Button Controls and Click Events

  • Thread starter Thread starter Alex Allage
  • Start date Start date
A

Alex Allage

Hello,
I am having a little problem. I have create a very basic shopping cart
site. In the process of displaying items in the shop, I am using image
buttons so that you may click on them and display detailed information
for that item, and another button which allows you to add the item to
your shopping cart. However, for some reason the events do not fire
correctly, or when they do it seems that it is the prior buttons
properties which are passed to the event handeler for that button. I
was wondering if anyone could help me with what it is I am doing wrong.
Thank you all in advance for your help.

Alex.

Example of the button being added, i use the id to determin the id of
the item click so that i can pull the correct data from the database.

ImageButton imgBut = new ImageButton();
iNormCount ++;
imgBut.ID = "imgBut" + iNormCount.ToString() + "-" +
drRow[dbDef.Df_tbl_DShop.fitbl_DShop.ID].ToString();
imgBut.CommandArgument =
drRow[dbDef.Df_tbl_DShop.fitbl_DShop.ID].ToString();
imgBut.Width = 96;
imgBut.Height = 115;
imgBut.ImageUrl = sImageURL;
imgBut.EnableViewState = true;
imgBut.Click +=new ImageClickEventHandler(imgBut_Click);

pnlPanel.Controls.Add(imgBut);
 
Back
Top