josh josh - 3 months ago 36
ASP.NET (C#) Question

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 Clip
{
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;
}
}
}
}

Answer

Use ASP checkbox instead of Html input type checkbox

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