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

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


No comments:

Post a Comment

There was an error in this gadget