简体   繁体   中英

how to call javascript function written in c#, onkeypress of a button in c#

i have written a javascript code in c# given below and i want to call it on 'onkeypress' event on a button in c#, how to do it

void Js()
{
    string js = "<script type='text/javascript' > 
                  function myfunction()
                      { 
                          alert(1); 
                       }
                    </script>";

}

and calling it on page load like

textbox1.Attributes.Add("onKeypress", " return myfunction();");
string js = "string js = "<script type='text/javascript'>"+
                  "function myfunction(){"+
                          "alert(1); "+
                      " } </script>";

Response.Write(js);
textbox1.Attributes.Add("onKeypress", " return myfunction();");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM