c# - How to get IDs of dynamically generated controls(buttons) in update panel -


webform2.aspx

<div>   <asp:scriptmanager id="scriptmanager1" runat="server"></asp:scriptmanager>        <asp:updatepanel id="updatepanel1" runat="server">          <contenttemplate>               <asp:placeholder id="placeholder1" runat="server"></asp:placeholder>           </contenttemplate>                 <triggers>                     <asp:asyncpostbacktrigger controlid="btnquestions" eventname="click" />                 </triggers>             </asp:updatepanel>              <asp:button id="btnquestions" runat="server" text="list of questions" onclick="btnquestions_click" />         </div> 

webform2.aspx.cs

 protected void btnquestions_click(object sender, eventargs e)         {             (int = 1; < 6; i++)             {                 button btn = new button();                 btn.id = i.tostring();                 btn.text = "goto question no. - " + i.tostring();                 placeholder1.controls.add(btn);             }         } 

view page source

<html xmlns="http://www.w3.org/1999/xhtml"> <head><title>  </title></head> <body>     <form method="post" action="webform2.aspx" id="form1"> <div class="aspnethidden"> <input type="hidden" name="__eventtarget" id="__eventtarget" value="" /> <input type="hidden" name="__eventargument" id="__eventargument" value="" /> <input type="hidden" name="__viewstate" id="__viewstate" value="/wepdwujmzc1mjk4otk4zgsuduk/vecpfioingmdp9kj5zbqvtzpcn6wnvbaesjwew==" /> </div>  <script type="text/javascript"> //<![cdata[ var theform = document.forms['form1']; if (!theform) {     theform = document.form1; } function __dopostback(eventtarget, eventargument) {     if (!theform.onsubmit || (theform.onsubmit() != false)) {         theform.__eventtarget.value = eventtarget;         theform.__eventargument.value = eventargument;         theform.submit();     } } //]]> </script>   <script src="/webresource.axd?d=qdmym63umpmu1djtvfnuusbvrfxrh_dboioxtsipzrgeov32_hkwuqebyxbgt2nvbpk_bflrvvswnb3de41ss01novbpis0qalvwdw91esk1&amp;t=635145356180000000" type="text/javascript"></script>   <script src="/scriptresource.axd?d=jwzamvqvpitgxutxhqhsnos-rvweugrjeumx8fcasewlh6pc_b5u6dbcemqjr6qsulralpurr460-ujmc0zmigfsemgkdslzbsyjmuf2cozi1il-snrjhvkvxahayuzhup0efco09uva7frupssjv6acusy1gk8fbgpd08kqzykpdkpgdgnk4k5ew51wzgfe0&amp;t=ca758f3" type="text/javascript"></script> <script type="text/javascript"> //<![cdata[ if (typeof(sys) === 'undefined') throw new error('asp.net ajax client-side framework failed load.'); //]]> </script>  <script src="/scriptresource.axd?d=aerobgsei2hf_mwyw0oq_sh_za3-vbrjupjkdbinvwjho4rvkxysp2rinq9ypkbtiut6al0xtxohspgmg8h-vo74_u918ejqooiapzfgxexsrmud9zp6fc_nyvi-aensmx2mzra4s4usb0zwsyhn2t96dyvruvfcu6aktikdgd_fsuvavd0xxk9x_quqdz980&amp;t=ca758f3" type="text/javascript"></script> <div class="aspnethidden">      <input type="hidden" name="__eventvalidation" id="__eventvalidation" value="/wedaak/bowzl5vcjjwbsbqele4f+xa+can637jozcaf7/zpzrl/rnrclqxrlwwoflpnj5phdomhrazcbvdd/csqhzug" /> </div>     <div>                 <script type="text/javascript"> //<![cdata[ sys.webforms.pagerequestmanager._initialize('scriptmanager1', 'form1', ['tupdatepanel1','updatepanel1'], ['btnquestions','btnquestions'], [], 90, ''); //]]> </script>          <div id="updatepanel1">    </div>          <input type="submit" name="btnquestions" value="list of questions" id="btnquestions" />     </div>     </form> </body> </html> 

question want call java-script function on dynamically generated button controls. but, in view page source there no such following code under updatepanel1.

<input type="submit" name="1" value="goto question no. - 1" id="1" /> <input type="submit" name="2" value="goto question no. - 2" id="2" /> <input type="submit" name="3" value="goto question no. - 3" id="3" /> <input type="submit" name="4" value="goto question no. - 4" id="4" /> <input type="submit" name="5" value="goto question no. - 5" id="5" /> 

also, don't want postback page(as other functionalities affected ).

<asp:postbacktrigger controlid="btnquestions" /> 


Comments