In the CodeBehind, Page_Load event handler, copy the key word list client-side:
string keyWordList = string.Empty;
for (int i=0; i<m_KeyWordList.Length; i++)
{
if ( keyWordList.Length > 0 )
keyWordList += ",";
keyWordList += "new String('" + m_KeyWordList[i] + "')";
}
// keyWordList = "new String('word1'),new String('word2'), ...etc";
RegisterArrayDeclaration("JsKeyWordArrayArray", keyWordList);
// Add the validation script:
string validateTextBoxScript =
"<script language=JavaScript>\n" +
"function validateTextBox(elementRef)\n" +
"{\n" +
" var textBoxValue = elementRef.value;\n" +
"\n" +
" if ( textBoxValue == '' )\n" +
" return;\n" +
"\n" +
" for (var i=0; i<JsKeyWordArrayArray.length; i++)\n" +
" {\n" +
" if ( textBoxValue == JsKeyWordArrayArray[i] )\n" +
" alert('WARNING: The word ' + JsKeyWordArrayArray[i] + ' is black-listed.');\n" +
" }\n" +
"}\n" +
"</script>";
RegisterClientScriptBlock("ValidateTextBoxScriptScript", validateTextBoxScript);
// Add the client-side event handler to the TextBox:
TextBox1.Attributes.Add("onchange", "JavaScript: validateTextBox(this);");
NC...