In javascript, I want to compare the selected value from a dropdown list to a list of values from my C# code behind. I've tried passing a string list through a HiddenField, but I can't get past the problem of 'Unable to get property 'split' of undefined or null reference'.
Looking around Stackoverflow and elsewhere I've tried many variations of the following code but the 'split error' has me stymied.
<asp:HiddenField ID="HiddenFieldList" runat="server" />
//Code behind:
HiddenFieldList.Value = String.Join(",", ValuesList);
//javascript
var CSVList = document.getElementById("HiddenFieldList").value;
var HFList = [];
HFList = this.CSVList.split(',');
// hoping to get to here...
for(i = 0; i < HFList.length; i++)
{
if (DDL == HFList[i])
{
do stuff ;
break ;
}
}
Or...instead of assigning a string list to my hidden field should I pass an array?? Fwiw - the project is not MVC.
Edit: My code behind list is derived from values in a datatable column.
<script>ends with</script>and hasvar theArray = [...]' inside. At the client side you'll end up withtheArrayas a local variable.