CheckBox enabled=false check is always true

A

andyrich_1

I have noticed that setting a checkbox control to enabled=false results
in the checked property always returning true

I enable the checkbox using javascript on the client side so I can
change the checked value but this has no effect.

I have found a way around the problem by setting the checkbox's
viewstate to false. What is really strange is that textboxes do not
have the same problem.

I'd be interested if anyone has the answer to this.

Thanks,
Andy

**********************************************************
Here's the vb code
***********************************************************

Public Class WebForm1
Inherits System.Web.UI.Page
Private m_dtblAppliedDiscounts As DataTable
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents rp As System.Web.UI.WebControls.Repeater

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then


m_dtblAppliedDiscounts = New DataTable
m_dtblAppliedDiscounts.Columns.Add("bBool")
m_dtblAppliedDiscounts.Columns.Add("sSomeText")

Dim dr As DataRow = m_dtblAppliedDiscounts.NewRow
dr.Item("bBool") = True
dr.Item("sSomeText") = "TestText"
m_dtblAppliedDiscounts.Rows.Add(dr)

rp.DataSource = m_dtblAppliedDiscounts
rp.DataBind()
End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
For iNestedControl As Integer = 0 To rp.Controls.Count - 1
Dim bBool As Boolean =
CType(rp.Controls(iNestedControl).FindControl("chkTestCheck"),
Web.UI.WebControls.CheckBox).Checked
Dim sTestText As String =
CType(rp.Controls(iNestedControl).FindControl("txtTestText"),
Web.UI.WebControls.TextBox).Text
Next
End Sub
End Class



*******************************************************
And here's the webform
*******************************************************


<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="chkPostback.WebForm1"
enableViewState="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="vs_showGrid" content="True">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function enable(ctl)
{
var arControls;
var ctlParent;
alert('enable');
ctlParent=document.all[ctl];

arControls = ctlParent.getElementsByTagName("input")
for (var i =0; i < arControls.length; i++){
arControls.disabled=false;
}
arControls = ctlParent.getElementsByTagName("select")
for (var i =0; i < arControls.length; i++){
arControls.disabled=false;
}
arControls = ctlParent.getElementsByTagName("span")
for (var i =0; i < arControls.length; i++){
arControls.disabled=false;
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<div id="ctlTest" onclick="enable('ctlTest');">click here
<asp:Repeater id="rp" runat="server" >
<ItemTemplate>
hello
<asp:CheckBox ID="chkTestCheck" Runat=server
Checked='<%#DataBinder.Eval(Container.DataItem, "bBool") %>'
EnableViewState="false" Enabled="false">
</asp:CheckBox>
<asp:TextBox ID="txtTestText" Runat=server Enabled=False
text=' said:
</asp:TextBox>
</ItemTemplate>
</asp:Repeater>
<br>
</div>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top