hi, post your code andd tell me what browser are you using ?
hi, if you dont want to do AutoPostback use my first approach
hi, refer below code, here i have wriiten in javascript and it;s working fine in IE, simply you can do in server-side also if you dont wish to use javascript
<script>
function EnableButtonAndImage() {
var count = 0;
var dataList = document.getElementById('<%= DataList.ClientID %>');
for (var index = 0; index < dataList.rows.length; index++) {
for (var cIndex = 0; cIndex < dataList.rows[index].cells.length; cIndex++) {
if (dataList.rows[index].cells[cIndex].childNodes[2].checked)
count++;
}
}
if (count > 0) {
document.getElementById('<%= Button1.ClientID %>').removeAttribute('disabled');
document.getElementById('<%= ibtnok.ClientID %>').removeAttribute('disabled');
}
else {
document.getElementById('<%= Button1.ClientID %>').setAttribute('disabled', 'true');
document.getElementById('<%= Button1.ClientID %>').setAttribute('disabled', 'true');
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:DataList ID="DataList" runat="server" RepeatDirection="Horizontal" CaptionAlign="Left">
<ItemTemplate>
<asp:ImageButton ID="btnImage" runat="server" />
<asp:CheckBox ID="Chkbox" runat="server" TextAlign="Right" onclick="EnableButtonAndImage()" />
</ItemTemplate>
</asp:DataList>
<asp:Button ID="Button1" runat="server" Enabled="false" Text="Delete" />
<asp:ImageButton ID="ibtnok" runat="server" Enabled="false" ImageUrl="~/Images/_Icon_Right_Extreme.gif" />
</form>
</body>
</html>
hurera1111
Member
175 Points
104 Posts
disable/enable outside asp button control on datalist checkbox checked javascript?
Feb 28, 2012 03:50 AM|LINK
I have a datalist inside that I am using a checkbox, I have 1 asp button and 2 image buttton which is outside of datalist something like this
<asp:DataList ID="dlst1" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dlst1_ItemDataBound" CaptionAlign="Left">
<ItemTemplate>
<asp:ImageButton ID="btnImage" runat="server" />
<asp:Label ID="lbl" runat="server"/>
<asp:CheckBox ID="Chkbox" runat="server" TextAlign="Right" />
</ItemTemplate>
</asp:DataList>
<asp:Button ID="Button1" runat="server" Enabled="false" Text="Delete" />
<asp:ImageButton ID="ibtnok" runat="server" Enabled="false" />
I want to enable the Button1 and ibtok when any one checkbox is checked and disable the Button1 and ibtnok when no checkbox is checked.
someone plz help me how to do that with javascript?
karthicks
All-Star
32102 Points
5523 Posts
Re: disable/enable outside asp button control on datalist checkbox checked javascript?
Feb 28, 2012 04:32 AM|LINK
hi, refer below code, here i have wriiten in javascript and it;s working fine in IE, simply you can do in server-side also if you dont wish to use javascript <script> function EnableButtonAndImage() { var count = 0; var dataList = document.getElementById('<%= DataList.ClientID %>'); for (var index = 0; index < dataList.rows.length; index++) { for (var cIndex = 0; cIndex < dataList.rows[index].cells.length; cIndex++) { if (dataList.rows[index].cells[cIndex].childNodes[2].checked) count++; } } if (count > 0) { document.getElementById('<%= Button1.ClientID %>').removeAttribute('disabled'); document.getElementById('<%= ibtnok.ClientID %>').removeAttribute('disabled'); } else { document.getElementById('<%= Button1.ClientID %>').setAttribute('disabled', 'true'); document.getElementById('<%= Button1.ClientID %>').setAttribute('disabled', 'true'); } } </script> </head> <body> <form id="form1" runat="server"> <asp:DataList ID="DataList" runat="server" RepeatDirection="Horizontal" CaptionAlign="Left"> <ItemTemplate> <asp:ImageButton ID="btnImage" runat="server" /> <asp:CheckBox ID="Chkbox" runat="server" TextAlign="Right" onclick="EnableButtonAndImage()" /> </ItemTemplate> </asp:DataList> <asp:Button ID="Button1" runat="server" Enabled="false" Text="Delete" /> <asp:ImageButton ID="ibtnok" runat="server" Enabled="false" ImageUrl="~/Images/_Icon_Right_Extreme.gif" /> </form> </body> </html>Server-Side Code <asp:DataList ID="DataList" runat="server" RepeatDirection="Horizontal" CaptionAlign="Left"> <ItemTemplate> <asp:ImageButton ID="btnImage" runat="server" /> <asp:CheckBox ID="Chkbox" runat="server" TextAlign="Right" OnCheckedChanged="Chkbox_CheckedChanged" AutoPostBack="true" /> </ItemTemplate> </asp:DataList> <asp:Button ID="Button1" runat="server" Enabled="false" Text="Delete" /> <asp:ImageButton ID="ibtnok" runat="server" Enabled="false" ImageUrl="~/Images/_Icon_Right_Extreme.gif" /> protected void Chkbox_CheckedChanged(object sender, EventArgs e) { int count = 0; for (int index = 0; index < this.DataList.Items.Count; index++) count = (this.DataList.Items[index].FindControl("Chkbox") as CheckBox).Checked ? ++count : count; this.Button1.Enabled = count > 0; this.ibtnok.Enabled = count > 0; }Karthick S
hurera1111
Member
175 Points
104 Posts
Re: disable/enable outside asp button control on datalist checkbox checked javascript?
Feb 28, 2012 05:00 AM|LINK
I don't want to use Autopostback="true", how to do that without autopost back
I have added a lbl and increase the index as childNodes[3], every time its going on else condition, count in not incrementing
chkbox is coming in 6th position that on span and inside the span input type is showing