Friday, February 18, 2011

Add javascript to ASP.NET server control

In code behind Page_Load
this.txtAddress.Attributes.Add("onchange", "txtAddress_onchange()");

In ASP.NET page markup
    <script language="javascript" type="text/javascript">
        function txtAddress_onchange() {
            //do stuff
        }
        </script>  

Note: This assumes I have a textbox with id txtAddress, and i want to add an "onchange" event.

References:
http://triaslama.wordpress.com/2008/04/25/calling-client-script-events-in-aspnet-server-controls/ 

No comments:

Post a Comment

There was an error in this gadget