c# 4.0 - After first click_event was fired, the second click_event does not fire -


i have 2 linkbuttons added dynamically depending on conditions, whether display 1 or another. these buttons have events also.

firstly displayed button's event fires, when conditions change , second button displayed, it's event not fire.

source code:

    //conditions     bool wanttochangeblogpost = false;     string textboxonchangeid = "";      protected void displayblogpost()     {         somearraylist[] arr = valuesfromddatabase();         foreach(blogpost y in arr)         {              string contentstr = y.blogmailingtext;//"some content in mailing";              //div displaying content in webpage             system.web.ui.htmlcontrols.htmlgenericcontrol contentdiv = new                      system.web.ui.htmlcontrols.htmlgenericcontrol("div");             contentdiv.innerhtml = contentstr;              //tb changes             textbox tbcontent = new textbox();             tbcontent.text = contentstr;             tbcontent.autopostback = true;             tbcontent.textmode = textboxmode.multiline;             tbcontent.wrap = true;             tbcontent.readonly = true;             tbcontent.enableviewstate = true;               //two different buttons cases, whether or not want change text                              //of blogpost             linkbutton changepost = new linkbutton();             changepost.text = "change mailingtext";             linkbutton savepost = new linkbutton();             savepost.text = "save changes";                   //id 's needed controls                 tbcontent.id = "content-" + y.id;                 contentdiv.id = "contentdiv-" + y.id;                      changepost.id = "changepost-" + y.id;                     savepost.id = "savepost-" + y.id;                      changepost.commandargument = "content-" + y.id;                     savepost.commandargument = "content-" + y.id;                //add these controls placeholder, defined in asmx:              //initially add contentdiv              myplaceholder.controls.add(contentdiv);                ///////////////////////////              //  here problem:  //              ///////////////////////////               //conditions determing when display 1 or linkbutton ,                                      //tbcontent              if (wanttochangeblogpost == true && textboxonchangeid == "content-" + y.id)                 {                      savepost.click += new eventhandler(save_click);             //here problem: event never fires :(                     contentdiv.innerhtml = "";                     tbcontent.readonly = false;                     tbcontent.visible = true;                      // button displayd when has clicked on button                              //'changepost'                     myplaceholder.controls.add(savepost);                 }              else                 {                     changepost.click += new eventhandler(changepost_click);                      contentdiv.innerhtml = contentstr;                                              tbcontent.readonly = true;                     tbcontent.visible = false;//initially tb not visible                      //initially bool false ,                     // button displayd                     myplaceholder.controls.add(changepost);                 }          }           //event methods both buttons          //after method completed want display linkbutton                              //'savepost' event 'save_click'         protected void changepost_click(object sender, eventargs e)         {             linkbutton lb = sender linkbutton;             //conditions             textboxonchangeid = lb.commandargument;             wanttochangeblogpost = true;             //go displaying method again             displayblogpost();         }          //this method never fires!  why??????         protected void save_click(object sender, eventargs e)         {             linkbutton lb = sender linkbutton;             //conditions             textboxonchangeid = "";             wanttochangeblogpost = false;                      //some logic send changed data database upload                                      //datatable                     uploadwithchangeddataintextbox();               //go displaying method again             displayblogpost();         }     } 

if adding controls dynamically have recreate on every post keeping id same event wiil fire

or if ur adding controls throught other method client side u can call

__dopostback(eventtarget,eventarg) , check id on server side , call sm function accordingly


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -