add a button click event dynamically in asp.net 4.5 c# -


i have questions post [1]: how can create dynamic button click event on dynamic button?

the solution not working me, created dynamically button, inside in asp:table controller.

i have try save dynamic elements in session, , allocate session value object in page_load, not working.

some ideas

edit:

        ...         button button = new button();         button.id = "btntag";         button.text = "tag generieren";         button.click += button_taggenerieren;          tabellenzelle.controls.add(button);         session["table"] = table;     }      public void button_taggenerieren(object sender, eventargs e)     {         tablerowcollection tabellenzeilen = qvtabelle.rows;         (int = 0; < tabellenzeilen.count; i++)         {             ...         }     }    protected void page_load(object sender, eventargs e)     {         if (!page.ispostback)         {              if (session["table"] != null)             {                 table = (table) session["table"];                 session["table"] = null;              }         }     } 

it not practice store every control session state.

only problem found need reload controls same id, when page posted server. otherwise, controls null.

<asp:placeholder runat="server" id="placeholder1" /> <asp:label runat="server" id="label1"/>  protected void page_load(object sender, eventargs e) {     loadcontrols(); }  private void loadcontrols() {     var button = new button {id = "btntag", text = "tag generieren"};     button.click += button_click;     placeholder1.controls.add(button); }  private void button_click(object sender, eventargs e) {     label1.text = "btntag button clicked"; } 

note: if not know button's id (which generated dynamically @ run time), want save ids in viewstate - https://stackoverflow.com/a/14449305/296861


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -