I have a javascript function that adds text to an asp:textbox. But once I try to save the textbox in the C# Codebehind, the textbox.Text property is still holding the original value, not the updated value. Here's the code
Javascript
function GetLanguages(e)
{
var newLang = e.nextSibling;
var checkedValues = '';
var chkEng = document.getElementById ("<%=chkEnglish.ClientID %>");
var chkFr = document.getElementById ("<%=chkFrench.ClientID %>");
var chkList1 = document.getElementById ("<%=chkTopLanguages.ClientID %>");
var arrayOfCheckBoxes = chkList1.getElementsByTagName("input");
var txtLangValue = document.getElementById("<%=txtLANG.ClientID %>");
if(chkEng.checked)
checkedValues = "English";
if(chkFr.checked)
{
if(checkedValues.length > 0)
checkedValues += ";";
checkedValues += "French";
}
for(var i=0;i<arrayOfCheckBoxes.length;i++)
{
var checkBoxRef = arrayOfCheckBoxes[i];
if(checkBoxRef.checked)
{
var labelArray = checkBoxRef.parentNode.getElementsByTagName('label');
if ( labelArray.length > 0 )
{
if ( checkedValues.length > 0 )
checkedValues += ";";
checkedValues += labelArray[0].innerHTML;
}
}
}
txtLangValue.value = checkedValues;
}
CodeBehind
List<string> lstItemsChecked = new List<string>(txtLANG.Text.Split(';'));
foreach (string language in lstItemsChecked)
{
foreach (DataRow row in dsTopLanguages.Tables[0].Rows)
{
if (row["Language"].ToString() == language)
{
if (strLanguages.Length > 0)
strLanguages += ";";
strLanguages += row["LanguageID"].ToString();
}
}
}
The txtLANG.Text.Split call results to the original value of the textbox, not the value updated via javascript