c# - Dynamic created radio buttons wont execute event on click -


i have button named "add radio button" in form, , text box named texbox1.

i've written code when click "add radio button", generates radio button; it's own name:

c#:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.htmlcontrols; using system.web.ui.webcontrols;  public partial class default2 : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {         if (!ispostback)         {             viewstate["counter"] = 0;         }     }     protected void button1_click(object sender, eventargs e)     {         (int = 0; <= convert.toint32(viewstate["counter"]); i++)         {             htmlgenericcontrol div = new htmlgenericcontrol("div");             radiobutton rb = new radiobutton();             rb.id = i.tostring();             rb.text = "button" + i.tostring();             rb.groupname = "rb";             rb.checkedchanged += radiobutton_checkedchanged;              div.controls.add(rb);             panel1.controls.add(div);         }          viewstate["counter"] = convert.toint32(viewstate["counter"]) + 1;     }     private void radiobutton_checkedchanged(object sender, eventargs e)     {         radiobutton btn = sender radiobutton;         textbox1.text = btn.text;     }  } 

asp

<%@ page language="c#" autoeventwireup="true" codefile="default2.aspx.cs" inherits="default2" %>  <!doctype html>  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>     <form id="form1" runat="server">     <div>          <asp:panel id="panel1" runat="server">         </asp:panel>         <br />         <asp:textbox id="textbox1" runat="server"></asp:textbox>         <br />         <br />         <asp:button id="button1" runat="server" onclick="button1_click" text="add radiobutton" />      </div>     </form> </body> </html> 

the problem after several radio buttons being created, want program work if each of them checked, textbox1.text gets radio button's text string (the name of button) function radiobutton_checkedchanged doesn't execute.

you missed think

rb.checkedchanged +=new eventhandler(rb_checkedchanged); 

check comments below also


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -