This blogs helps you to understand the concept of Binding Java Script event to Asp.net control in C#. Binding javascript event to an asp.net control in code behild (C#) code is follows,
Syntax
- Asp.net_control.Attributes.Add("Key", "Value");
Key - java script events for asp.net control
Value - Java script functions
Example code snippet
- Asp.net_control.Attributes.Add("onKeyPress", "javascript:return OnEnterKey(event,this)");
-
-
- Asp.netControl.Attributes.Add("readonly", "readonly");
- Asp.netControl.Attributes.Add("readonly", "readonly");
With the above mentioned code,
Asp.net controls are, textbox, datagrid, dropdown, label etc
Key - OnkeyPress, readonly, onclick
Value - OnClick, Onenterkey, etc - Mention java script function name.
With the above mentioned code, we can bind javascript to any asp.net control in C#; it depends on the required time.