I just want to call an ajax function on pressing the enter key and alt key.since i have a submit button,the form gets submitted if i press enter.Instead,an ajax function should be called when i press enter or alt.Also,i just want to do it with the help of ASCII values of those two buttons on keypress event.Help me!!
You will need to execute a function onkeypress:
Right now it will just alert you to the key pressed. Add this function to the onkeypress event as <input type="text" onkeypress="keypressed(event)">Code:function keypressed(evt){ var key = (evt) ? evt.which : event.keyCode; alert(String.fromCharCode(key)); // Later ..... if (String.fromCharCode(key)=="<char here>"){ // Do something } }
try below
Code:document.onkeydown=function(evt) { var isAltKey = (evt) ? evt.altKey : event.altKey; var key = (evt) ? evt.which : event.keyCode; if(isAltKey && key == 13) { //do ajax call here } };
EDIT: realized google had taken me into AJAX, not c#
Jordan, if you want to remove this, please do- wrong language
my apologies everyone... thought things looked odd lol
original post:
I know this is an older topic, but I found something else while working on a project. I too wanted the enter key to do something, here's what I came up with:
Works great for meCode:private void getData() { try { this.inventory_pricingTableAdapter.Fill(this.marksDataSet.inventory_pricing, partNumToolStripTextBox.Text); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } private void partNumToolStripTextBox_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { getData(); } }
Last edited by Parabola; 08-11-2009 at 07:35 AM. Reason: wrong language
Programmer (n): An organism that can turn caffeine into code.
Programming would be so much easier without all the users.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks