Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammattically added image button + click
    primarykey
    data
    text
    <p>I have a method where I am creating some image buttons. I added below line: btnCity.Click += new ImageClickEventHandler(btnCity_Click); to the method to code the click event.</p> <p>On @Jacek's request adding code where buttons are added:</p> <pre><code>private void LocateCities() { IDBManager dbManager = new DBManager(DataProvider.SqlServer); dbManager.ConnectionString = @"Data Source=server; Initial Catalog=db; Integrated Security = SSPI;"; try { dbManager.Open(); dbManager.CreateParameters(2); dbManager.AddParameters(0, "@Function", "All"); dbManager.AddParameters(1, "@Team", "All"); DataSet ds = new DataSet("Stuff"); ds = dbManager.ExecuteDataSet(CommandType.StoredProcedure, "sp_select_staff_and_cities"); foreach (DataRow dr in ds.Tables[0].Rows) { int xaxis = Convert.ToInt32(dr["xaxis"]) ; int yaxis = Convert.ToInt32(dr["yaxis"]) ; int textxaxis = xaxis + 30; int textyaxis = yaxis - 10; ImageButton btnCity = new ImageButton(); btnCity.ImageUrl = "~/Images/cyanball1.gif"; btnCity.Height = 10; btnCity.Attributes.Add("style", "Z-INDEX:100; POSITION:relative; left:" + xaxis + "px; TOP:" + yaxis + "px; Left:10px;Right:10px"); Label lblCity = new Label(); lblCity.Text = dr["city"].ToString(); lblCity.Attributes.Add("style", "Z-INDEX: 100;POSITION:relative; left:" + textxaxis + "px; TOP:" + textyaxis + "px"); PanelMap.Controls.Add(lblCity); PanelMap.Controls.Add(btnCity); } } catch (Exception ex) { Response.Write(ex.ToString()); } finally { dbManager.Dispose(); } } </code></pre> <p>I also created below method to handle click event:</p> <pre><code> void btnCity_Click(object sender, ImageClickEventArgs e) { ImageButton btnCity = (ImageButton)sender; Response.Write("works"); } </code></pre> <p>but it doesn't work. Any suggestions how it should look like?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload