Given a Web Forms project inherited by me, I am relatively new to the field of Web development. The page in question features 2 listboxes: lstCaseLoad, containing "Caseloads" (ID numbers), and lstAssignedCaseLoad, filled with Caseloads chosen by the Form User. Users can select Caseloads from lstCaseLoad and use a button to transfer them to lstAssignedCaseLoad using client-side JavaScript. Additionally, users can also remove Caseloads from lstAssigned and move them back to lstCaseLoad on the client side. To save these changes to SQL, the user must click a submit button.
The process of adding new CaseLoads from lstCaseloads to lstAssigned and submitting is functioning properly. However, I am encountering difficulties when attempting to remove items from lstAssigned. It appears that lstAssigned becomes null during submission, preventing successful saving. Please see the code snippet below for reference:
Listboxes:
<asp:ListBox ID="lstCaseLoad" runat="server" SelectionMode="Multiple" />
<asp:ListBox ID="lstAssignedCaseLoad" runat="server" Height="175px" SelectionMode="Multiple" />
//Adding Caseload to Assigned
$("#btnAddCaseLoad").bind("click", function () {
var options = $("[id*=lstCaseLoad] option:selected");
$("[id*=lstAssignedCaseLoad]").append($(options).clone());
$(options).remove();
return false;
});
//Removing Caseload from Assigned
$("#btnRemoveCaseLoad").bind("click", function () {
var options = $("[id*=lstAssignedCaseLoad] option:selected");
$("[id*=lstCaseLoad]").append($(options).clone());
$(options).remove();
return false;
});
Code Behind
protected void Page_Load()
{
if (!IsPostBack)
{
//Retrieving and Binding listboxes. No issues here
GetData();
BindData();
}
else
{
var test= Request.Form.AllKeys;
//Temp variable to check all elements for debugging. lstAssignedCaseLoad is missing when deleting. Is fine when adding new caseload
//Read listAssignedCaseLoad items to comma seperated strings. Becomes null when trying to remove items
string strCaseLoad = Request.Form[lstAssignedCaseLoad.UniqueID];
//Transfer string strCaseload to (field)List<string> for saving. Works fine when string is not empty
userCaseLoadList = ProcessListString(strCaseLoad, lstAssignedCaseLoad);
}
}
//Submit button method. Works as intended
protected void EditUser_Click(object sender, EventArgs e)
{
identityMgr.EditUser(Email.Text, userRoleList, userCaseLoadList);
}
I have tried searching for solutions but haven't been able to find an exact match for this issue. Thank you for your time and assistance!