asp.net - Why am I having trouble selecting a default radio button on a web page? -


it seems ought dead simple, i'm stuck. i've written asp.net code outputs pair of radio buttons:

<p> <label for='chkyapper'>yapper</label> <input type='radio' name='yapper' id='chkyapper' value='yapper' checked='<%=gblyapperchecked %>' /> <br /> <label for='chknonyapper'>non-yapper</label> <input type='radio' name='yapper' id='chknonyapper' value='nonyapper' checked='<%=gblnonyapperchecked %>' />     

        if (registrationuser.isyapper == 1)         {             gblyapperchecked = "checked";             gblnonyapperchecked = "";         }         else         {             gblyapperchecked = "";             gblnonyapperchecked = "checked";         } 

as expected, 2 radio buttons, "yapper" , "non-yapper". however, when step thru code , see gblyapperchecked "checked" , gblnonyapperchecked "", non-yapper selected default in web browser.

what doing wrong?

updatehere html code appears in browser. "yapper" should selected, "non-yapper" appears selected instead.

<p> <label for='chkyapper'>yapper</label> <input type='radio' name='yapper' id='chkyapper' value='yapper' checked='checked' /> <br /> <label for='chknonyapper'>non-yapper</label> <input type='radio' name='yapper' id='chknonyapper' value='nonyapper' checked='' />     

note html "checked" attribute determined being present or not present. see http://www.w3.org/tr/html401/interact/forms.html#adef-checked spec.

in particular means if want checked cna have checked, checked=true, checked=checked , on. want not have checked attribute @ if don't want checkbox selected.

i advise structure such as:

<input type='radio' name='yapper' id='chknonyapper' value='nonyapper' <%=registrationuser.isyapper?"":"checked='checked'" %> /> 

this should eliminate checked attribute entirely dependant on isyapper boolean.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -