I encountered a strange issue with a JavaScript function I have to enable a listbox that is disabled when it loads. The function works perfectly to enable or disable the listbox. However, after the user clicks the save button, it does not capture the newly selected item and instead retains the old selected item from databind. I have checked the isPostback on Page load and if it is not a postback, the listbox is not loaded again. Can anyone provide a hint to help me solve this problem? Thanks in advance.
function enableProject() {
var chk = document.getElementById('chkProject');
if (chk.checked) {
document.getElementById('listProject').disabled = false;
}
else {
document.getElementById('listProject').disabled = true;
}
}
Below is my ASP.NET page:
<asp:ListBox id="listProject" runat="server"
SelectionMode="Multiple" Rows="5" class="w200" Enabled="false"/>
<asp:checkbox id="chkProject" runat="server"
Text="Enable" onclick="enableProject()" />
The code snippet below is for checking the ListBox
:
For Each projectItem In listProject.Items
If projectItem.Selected Then
'create a new project object
Dim objProj As New Data.Project( ID, projectItem.Value)
objProjects.Add Project(objProj)
End If
Next