I'm building a set of text boxes from asp.net repeater and trying to add a key down event from C# code to those text boxes to prevent user from entering a specific character (comma(,)). I can't use the text box id itself in Javascript because its built dynamically with diff id's. Now I have no idea how to pass the e object to the textbox's keydown event from C#.
Any suggestion is much appreciated.
Code Snippet :
TextBox txtTextField = e.Item.FindControl("txtAns_1") as TextBox;
txtTextField.Attributes.Add("keydown", "PreventChars(" + txtTextField +")");
Javascript
function PreventChars(e) {
var k = String.fromCharCode(e.which);
if (k.match(/,/g))
{
e.preventDefault();
}
};