.net - Radio option GroupName problem in Dynamic loading user Control ASP.net -
i have user control
<table style="border-width: 0">     <tr>         <td style="vertical-align: middle;">             <asp:radiobutton id="rdoption" runat="server" text="i m testing"                   groupname="questions" oncheckedchanged="rdoption_checkedchanged"                  autopostback="true"/>         </td>         <td style="vertical-align: middle; padding-left: 10px">             <asp:textbox id="txtothers" runat="server" cssclass="txtbox" visible="false"></asp:textbox>         </td>     </tr> </table>  protected void page_load(object sender, eventargs e)     {         rdoption.groupname = "mygroup";         rdoption.text = option.optiondesc;     } on survery.aspx loaded user control dynamically
 foreach (clsoptions option in _currentquestion.options)         {             usercontrols_optionfield ctrl = page.loadcontrol("~/usercontrols/optionfield.ascx") usercontrols_optionfield;             ctrl.option = option;             pnloption.controls.add(ctrl);         } problem each option have diffrent group name shown below. thats why options not working , option can selected while in mcqs 1 option can selected.
<input id="contentplaceholder1_ctl01_rdoption" type="radio" name="ctl00$contentplaceholder1$ctl01$mygroup" value="rdoption">  <input id="contentplaceholder1_ctl02_rdoption" type="radio" name="ctl00$contentplaceholder1$ctl02$mygroup" value="rdoption"> 
i think bug in asp.net since 1.0(awesome, have forgotten ^^).
you try following solution works repeater(or databound control) should work dynamic usercontrols.
the problem asp.net renders different unique names different namingcontainers , therefore radiobuttons different groupnames.
put in head section of page's:
function setuniqueradiobutton(nameregex, current) {       re = new regexp(nameregex);       for(i = 0; < document.forms[0].elements.length; i++)       {             elm = document.forms[0].elements[i]             if (elm.type == 'radio')             {                   if (re.test(elm.name))                   {                           elm.checked = false;                   }              }       }       current.checked = true; } add clientside onclick event radiobuttons appropriate parameters:
string script = "setuniqueradiobutton('rdoption.*mygroup',this)"; rdoption.attributes.add("onclick", script); [not tested]
Comments
Post a Comment