0

I am new to asp.net and c# and have to deal with the event handling for a dynamically created table. The Background:

I have a method in my code-behind CSS file and there, I create dynamically a table to show users in the first column and for every user, I have a checkbox in the second column. My table is displayed well, so the creation is not the problem.

My problem is, that I need event-handling. The goal is, to "mark" users by clicking their appropriate checkbox and then to do, whatever I should do with such users.

I have added the code for event handling with "+=" and I have also tried to use an event handler object. But the problem is: my event-handling code is never reached (i checked this by running and debugging the code).

I'm totally new to asp.net and c# and HTML, javascript and so on. So i don't know much about page-life-cycle and things like that. And it will last time, to get in, cause im a student and I'm just working 2 days a week. If anybody can explain me, how I can do event handling in c# and asp.net for dynamically created elements, that would help me much. Thanks for every help :)

foreach (ListItem li in list_deletedUsers.Items)
            {
                String s = li.Text;
                //Creating the basic Elements
                TableRow myrow = new TableRow();
                TableCell cellone = new TableCell();
                TableCell celltwo = new TableCell();
                CheckBox cb = new CheckBox();
                //cb.CheckedChanged += cb_CheckedChanged;
                //cb.CheckedChanged += this.cb_CheckedChanged; 

                //cb.CheckedChanged += new 
                System.EventHandler(cb_CheckedChanged); 
                //Setting the values and adding cells to row
                cellone.Text = s;
                myrow.Cells.Add(cellone);
                celltwo.Controls.Add(cb);
                celltwo.ApplyStyle(tableStyle);
                myrow.Cells.Add(celltwo);
                //Third Column Cell for further use
                //TableCell cellthree = new TableCell();
                //cellthree.BackColor = System.Drawing.Color.AliceBlue;
                //Adding to Row
                //myrow.Cells.Add(cellthree);
                //Adding to TableBert
                TableBert.Rows.Add(myrow);
            }

Here in this methode i create the table:

public void rbe_changed(object sender, EventArgs e)
{
   //do some stuff
   //look for the user list
   //create the table like i show above
}
  • 2
    Welcome to Stack Overflow! It seems you have a problem with your code. However, we can't help unless we have [code or information that can reproduce the problem](//stackoverflow.com/help/mcve). Otherwise, we are just blindly guessing. – rene Sep 29 '17 at 09:59
  • see also: https://stackoverflow.com/questions/19598141/dynamic-event-handler-not-firing among [others](https://stackoverflow.com/search?q=dynamic+%5Basp.net%5D+events+hasaccepted%3Ayes). Try that first. – rene Sep 29 '17 at 10:00
  • Hi i can show here the code snippet for the talbe, just one moment :) – SourceCookie Sep 29 '17 at 10:18
  • So i put in a code snippet above :) – SourceCookie Sep 29 '17 at 10:23
  • im not sure, if its enough, i hope for feedback :D – SourceCookie Sep 29 '17 at 10:24
  • where do you run this code? In which page event? – rene Sep 29 '17 at 10:26
  • Hi Rene, no i dont run this code in page event. Im not really know, what a page event is (im really new to web developement). I have 5 radio buttons on the page. If i select a radio button, the corresponding list of users is displayed. But my chief wants something new. He wants for a special group of that users (selected by one of this radiobuttons) the posibility to "mark" that users. so i made a table and in every row a have a user and a checkbox for that user. The code is run, if radiobutton state has changed – SourceCookie Sep 29 '17 at 11:16
  • i can show a bit above in the code – SourceCookie Sep 29 '17 at 11:17

0 Answers0