If you want to configure a .NET handler for the keypress
event, you should take a look at DOM Events.
The following sample code demonstrates how to add DOM event listener to the element:
DOMEventHandler domEvent = delegate(object sender, DOMEventArgs e)
{
DOMEventType eventType = e.Type;
Console.Out.WriteLine("handled event = " + eventType);
};
element.AddEventListener(DOMEventType.OnKeyPress, domEvent, false);
In addition, you need to take into account that modifying the element attribute may have no effect on its property:
What is the difference between properties and attributes in HTML?