josh
josh

Reputation: 123

Forms checkbox.Checked not recognised

I'm having troubles with recognizing .Checked. I'm getting this error

'HtmlGenericControl' does not contain a definition for 'Checked' and no extension method 'Checked'

Which namespace am I missing/not have to use the .Checked property?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Radio1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Radio1.SelectedIndex == 0)
            {
                Checkbox1.Visible = true;
            }
            else
            {
                Checkbox1.Visible = false;
                Checkbox1.Checked = false;
            }
        }
    }
}

Upvotes: 0

Views: 114

Answers (2)

hari
hari

Reputation: 1

I guess you didn't set the property Autopostback = "true" for radiobutton list.

 <asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="True">
            <asp:ListItem Value="1" Text="1">                </asp:ListItem>
            <asp:ListItem Value="2" Text="2">            </asp:ListItem>
        </asp:RadioButtonList>
        <asp:CheckBox ID="CheckBox1" runat="server" />

Upvotes: 0

Anant Dabhi
Anant Dabhi

Reputation: 11104

Use ASP checkbox instead of Html input type checkbox

<asp:CheckBox ID="CheckBox1" runat="server" oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="true" />

Upvotes: 1

Related Questions