need help on how to detect which one of the dynamically loaded button fired the event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • axxon
    New Member
    • Jul 2007
    • 6

    need help on how to detect which one of the dynamically loaded button fired the event

    Hi guys! I am at my wits end detecting which one of the dymically loaded button fired the click event(since they all have same ID and text value)
    Heres the scenario:

    I have created a loop to read through the records of a table and creat dynamic buttons. I have also created the button_click event. But in the event handler I can not figure out at which point of the iteration the event was fired!!

    my code is:
    ///////////// creating the button /////////////////////////
    protected void Page_Load(objec t sender, EventArgs e)
    {
    while (reader.Read())
    {
    Panel panel= new Panel();
    Table t= new Table();
    TableCell c3 = new TableCell();
    Button button1 = new Button();
    button1.Text = "hide";
    button1.Click += new EventHandler(bu tton1_Click);
    c3.Controls.Add (button1);

    TableRow r = new TableRow();
    r.Cells.Add(c3) ;
    t.Rows.Add(r);
    panel.Controls. Add(t);
    }
    }
    /////////////// then in the event handler button1_click i need to figure out which one of the buttons fired this event, because by that I wish to figure out at which iteration of the loop the event-firing-button was created //////////////////////////

    void button1_Click(o bject sender, EventArgs e)
    {

    }

    any idea how to do that?i need to know it and i need it fast..!!
    please help
    thanx in advance!
  • axxon
    New Member
    • Jul 2007
    • 6

    #2
    guys hellpp...!!gosh no body replied...!!

    Comment

    • legolas936
      New Member
      • Jul 2007
      • 4

      #3
      Originally posted by axxon
      guys hellpp...!!gosh no body replied...!!

      I have an idea, but i am not very sure of this, just give it a try.Each of the Buttons has a seperate ClientId. if u could store them while u create them then u could run a loop in the event handler to find out which button fired the event.

      And one more thing if u can replace the Button with a RadioButton and place one Submit button i can give u the exact solution

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Originally posted by axxon
        guys hellpp...!!gosh no body replied...!!
        why did you post this in the asp forum? You aren't asking anything remotely related to asp. Some of us might be able to piece together a solution, but asp is a server-side technology. It does not relate in any way to client-side events and actions like button clicks.

        Jared

        Comment

        Working...