Sunday, April 29, 2012

Catch Enter on ASP Form example

1st thing u must know - u cant do it directly like any other controls.OnTextChange
therefor the good lord gave us JS!
put this script on:
<script language="javascript" type="text/javascript">   
   document.onkeypress = function() {      
      if (window.event.keyCode==13){
          alert(window.event.keyCode); //to see that it works      

This on the aspx page :
<input id="Hidden1" type="hidden" runat="server"/>

and on the cs page:
protected void Page_Load(object sender, EventArgs e)
    if (Hidden1.Value == "true")
         TextBox1.Text = "We Got an Enter to the Server Side";
         TextBox1.Text = "just a page load, no enter";        
//put a TextBox with width 300, run the page and press enter :)

No comments:

Post a Comment