Search code examples
c#asp.netascx

asp RadioButton not selected when Checked="true"


I have two radio buttons "Yes" and "No" and I want the "No" radio button to be selected by default. However, I can't get it be be selected through the asp code or by the code behind. Am I doing this completely wrong or did I just miss something.

ASP code:

<div class="query_header" runat="server" id="ScanOnStartup">
    <div class="formlabel" style="width: 300px">Perform Scan on startup</div>
    <div class="formfield" style="line-height: 10px">
        <asp:RadioButton ID="scanOnStartupYes" Text="Yes" GroupName="ScanOnStartupRadio" runat="server" AutoPostBack="false"  Checked="false"/>&nbsp
        <asp:RadioButton ID="sanOnStartupNo" Text="No" GroupName="ScanOnStartupRadio" runat="server" AutoPostBack="false"  Checked="true"/>
    </div>
    <div class="formdivider"></div>
</div>

Code behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {               
                this.scanOnStartupNo.Checked = true;

        }

Solution

  • Okay aside from the typo "sanOnStartupNo", I know where the problem is coming from. There was actually another control from my code behind that renders the page and that is where the selection for the radio button is being set. I added in code for my radio button and it works now.