Adf.Web.UI.CharacterFilteringTextBox.RegisterClientScriptFunction C# (CSharp) Method

RegisterClientScriptFunction() protected method

Creates default code for the descendants and puts the specified special JavaScript code (innerCode) from the descendants inside the created function.
protected RegisterClientScriptFunction ( string innerCode ) : void
innerCode string The descendant dependent JavaScript code.
return void
        protected void RegisterClientScriptFunction(string innerCode)
        {
            // Check if the function has already been registered,
            // before we're doing more than strictly needed.
            if (!Page.ClientScript.IsClientScriptBlockRegistered(OnKeyPressFunctionName))
            {
                StringBuilder jsCode = new StringBuilder();

                jsCode.Append("<script language=\"javascript\"><!--\n");
                jsCode.Append("function " + OnKeyPressFunctionName + "(evt)");
                jsCode.Append("{" + "	evt = (evt) ? evt : ((window.event) ? event : null);" + "	if (evt)" + "	{" + "		var charCode = (evt.charCode) ? evt.charCode :" + "		((evt.keyCode) ? evt.keyCode : " + "		((evt.which) ? evt.which : 0));" + "		var ch = String.fromCharCode(charCode);");

                // Add the code from the descendant whitch implements valid key's and characters.
                jsCode.Append(innerCode);

                if (AllowAltKey) jsCode.Append(altKey).Append("\n");
                if (AllowCtrlKey) jsCode.Append(ctrlKey).Append("\n");
                if (AllowArrowKeys) jsCode.Append(arrowKeys).Append("\n");
                if (AllowDecimalSeparatorKey) jsCode.Append(_numberDecimalSeparatorKey).Append("\n");
                if (AllowFunctionKeys) jsCode.Append(functionKeys).Append("\n");
                if (AllowNegativeSignKey) jsCode.Append(_negativeSignKey).Append("\n");
                if (AllowNumericKeys) jsCode.Append(numericKeys).Append("\n");
                if (AllowSpaceKey) jsCode.Append(spaceKey).Append("\n");
                if (AllowSpecialKeys) jsCode.Append(specialKeys).Append("\n");

                jsCode.Append(@"
                            if (window.event) evt.returnValue = false;
                            else evt.preventDefault();
                        }
                    }
                ");
                jsCode.Append("\n--></script>");

                Page.ClientScript.RegisterClientScriptBlock(GetType(), //type of the control injecting the script
                                                            OnKeyPressFunctionName, // the name of the function
                                                            jsCode.ToString() // convert to string
                    );
            }
        }