Binding Java Script Event To ASP.NET Control In C#

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
  1. Asp.net_control.Attributes.Add("Key""Value");     
Key  - java script events for asp.net control
Value - Java script  functions
 
Example code snippet
  1. Asp.net_control.Attributes.Add("onKeyPress""javascript:return OnEnterKey(event,this)");   
  2.   
  3.   
  4.            Asp.netControl.Attributes.Add("readonly""readonly");  
  5.            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.