I have an application which is in .Net1.1 and upgraded to 3.5 using Visual studio 2008.
There is page which is having a checkbox and a list box which is enabled and disabled using Javascript if enabled we can select the items in List and upon button click the selected items will be processed.
The Selected items is working fine in .Net 1.1 but not in 3.5.I am giving sample code where I am facing the issue.The same code works fine in .Net1.1
Below are the aspx lines
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListBox.aspx.cs" Inherits="WebApplication1.ListBox" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>UsageReport</title>
<script language="javascript">
function isAllChecked()
{
var ctrlList = document.getElementById("lstUsers");
var allChecked = document.getElementById("chkAll");
var checked = allChecked.checked;
if (checked) {
ctrlList.disabled = true;
unselectItems();
}
else {
ctrlList.disabled = false;
}
}
function unselectItems()
{
var lstUsers = document.getElementById("lstUsers");
var list = lstUsers;
for (var i = 0; i < list.length; i ++)
{
list[i].selected = false;
}
list.selectedIndex = -1;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<table>
<tr>
<td>
</td>
<td>
<asp:CheckBox ID="chkAll" Checked="True" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:ListBox ID="lstUsers" runat="server" SelectionMode="Multiple" Enabled="false"></asp:ListBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</td>
</tr>
</table>
</form>
</body>
</html>
Below are the lines for CodeBehind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class ListBox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.chkAll.Attributes["onclick"] = "isAllChecked();";
lstUsers.DataSource = new string[] { "one", "two", "three" };
lstUsers.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (ListItem li in lstUsers.Items)
{
if(li.Selected)
Response.Write(li.Value);
}
}
}
}