how to find which imagebutton was clicked?
<p>I have created a function which displays a bus seat layout, dynamically. Now after adding all this dynamically created table and cells into a  tag, I want to know which imagebutton was clicked.I have also  mentioned proper ID to each imagebutton in cell.</p>

<pre><code>public void DisplaySeatLayout(ListBus _listBus) {
        //fetching data from database     
        SeatBUS _seatBUS = new SeatBUS();
        DataTable dt = _seatBUS.GetAllSeatByBusRouter(_listBus);

        //Layout generation code    
        ImageButton img ;
        HtmlTable table = new HtmlTable();
        table.Attributes.Add("runat", "server");
        table.Attributes.Add("id", "LayoutTable");

        HtmlTableRow [] tr = new HtmlTableRow[] { new HtmlTableRow(), new HtmlTableRow(), new HtmlTableRow(),new HtmlTableRow(),new HtmlTableRow()};
        HtmlTableCell tc = null;
        int SeatNo=0;
        //Getting Total no of seats.
        int MaxSeatNo = dt.Rows.Count;
        //Iterating datatable

            //Displaying labels for displaying column names in the table
            for (int columnCounter = 0; columnCounter &lt; 8; columnCounter++){

                for (int rowCounter = 0; rowCounter &lt; 5; rowCounter++){

                    if (SeatNo &lt; MaxSeatNo){
                            if (rowCounter == 2 &amp;&amp; columnCounter &lt; 7){
                                tc = new HtmlTableCell();
                                Label lbl = new Label();
                                lbl.Text = "";
                                lbl.ID = "lbl " + rowCounter.ToString() + columnCounter.ToString();

                                tc.Controls.Add(lbl);
                                tr[rowCounter].Controls.Add(tc);
                                //reducing seat number for sake of sequence.

                            }
                            else{
                                //adding label in each cell.
                                tc = new HtmlTableCell();
                                Label lbl = new Label();
                                lbl.Text = dt.Rows[SeatNo]["NumberSeat"].ToString();
                                lbl.ID = "lbl " + rowCounter.ToString() + columnCounter.ToString();

                                tc.Controls.Add(lbl);
                                //adding imagebutton in each cell . 
                                img = new ImageButton();
                                img.Attributes.Add("type", "image");
                                img.Attributes.Add("id", rowCounter.ToString());
                                img.CssClass = "seatRightMostRow1";
                                img.ImageUrl = "../Images/available_seat_img.png";
                                img.ID = dt.Rows[SeatNo]["NumberSeat"].ToString();
                                img.Click += new ImageClickEventHandler(Imagebutton_Click);
                                tc.Controls.Add(img);
                                tr[rowCounter].Controls.Add(tc);
                                SeatNo++;
                            }
                    }//SeatNo &lt; MaxSeatNo
                  table.Controls.Add(tr[rowCounter]);
                }
                seatArranngement.Controls.Add(table);
            }

}
</code></pre>

<p>this is complete code after suggestion.
function that is displaying dynamic table is inside Page_load</p>

<pre><code>     protected void Page_Load(object sender, EventArgs e)
     {
      _listBusBUS = new ListBusBUS();
       _routerBUS = new RouterBUS();
      _listBus = new ListBus();
      _promoteBUS = new PromoteBUS(); 

       if (!Page.IsPostBack)
      {
          LoadData();

      }
      DisplaySeatLayout();
    }
</code></pre>

<p>Also here i have copied code in prerender</p>

<pre><code>     protected override void OnPreRender(EventArgs e)
     {
    if (MultiView1.ActiveViewIndex == 1)
    {
        int listBusID = int.Parse(hdlListBusID.Value.ToString());
        _listBus = _listBusBUS.GetAllListBusById(listBusID);

        litListBusID.Text = _listBus.ListBusID.ToString();
        litRouterID.Text = _listBus.RouterID.ToString();
        litArrival.Text = _listBus.Arrival.ToString();
        litDeparture.Text = _listBus.Departure.ToString();
        litPrice.Text = _listBus.Price.ToString();
    }
    else if (MultiView1.ActiveViewIndex == 2)
    {

        //original code starts from here
        litListBusIDS.Text = litListBusIDS.Text;
        litRouterIDS.Text = litRouterID.Text;
        litArrivalS.Text = litArrival.Text;
        litDepartureS.Text = litDeparture.Text;
        litSeat.Text = hdlSeat.Value;// chkSeat.SelectedItem.Text;


        litPrices.Text = litPrice.Text;
        //hdlSeat.Value = chkSeat.SelectedItem.Text.ToString();
    }
    else if (MultiView1.ActiveViewIndex == 3)
    {
        litCustomerNameStep4.Text = txtcustomername.Text;
        litSeatStep4.Text = litSeat.Text;
        litPriceStep4.Text = litPrices.Text;
    }
    base.PreRender(e);
}
</code></pre>

<p>Also, layout is getting created twice if i click on any imagebutton.</p>
