Oh the problem is with how the asp page wires up with the functions that you have. There is a "__doPostBack()" javascript function which is created in the "generated" web page from the ASP code.
I can help you to wireup the page correctly, but take a look at this code. It was done in VS2005. My apologizes ... VS2002 needs a little reinstalling and lazy to fix that today.
Default.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<script language="javascript" id="trapEnterScript" type="text/javascript">
function trapEnter()
{
//IE 6 code
window.status= "Key pressed has code = '" + event.keyCode + "'";
if(event.keyCode == 32)//space key
{
//call do post back
__doPostBack('doNothing','');
}
else
{
event.returnValue = false;//use up the event, rather cancel the event, so that no key is written in the text box
}
//IE 6 code ends
}
</script>
<div>
<input id="Button1" type="button" value="button" onserverclick="Button1_ServerClick" runat="server" /><br />
<input id="Text1" type="text" onkeydown="trapEnter();" />
<input id="Text2" type="text" onkeydown="trapEnter();" />
<input id="Text3" type="text" onkeydown="trapEnter();" /><br />
<input id="doNothing" type="button" value="Do nothing" onclick="return;" onserverclick="DoNothing_ServerClick" runat="server" /></div>
</form>
</body>
</html>
Default.aspx.cs
Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_ServerClick(object sender, EventArgs e)
{
Page.Response.Write("This is a post back<br>");
}
protected void DoNothing_ServerClick(object sender, EventArgs e)
{
//doNothing 'onclick' has a 'return' javascript code which blocks the following postback call of these functions. See DoNothing attributes
DoThis1();
DoThis2();
DoThis3();
}
protected void DoThis1()
{
Page.Response.Write("This 1 was done<br>");
}
protected void DoThis2()
{
Page.Response.Write("This 2 was done<br>");
}
protected void DoThis3()
{
Page.Response.Write("This 3 was done<br>");
}
}
Notice that I called "__doPostBack('doNothing','');" to a control with id doNothing. This basically sends or submitts the form, but the parameter, or control id, is used by the server to start a server event handle which needs an object sender and argument ie EventHandler(Object, Args). The easiest way to wire up a control id to a server event handle is to create a dummy server control and 'double click' it and it wires up atomatically, and the you manually uses that dummy control id in the "__doPostBack" function and summon the sever event handler. Note too I used html controls and not server controls.
I messed up the trap code for the enter key. I said before that the focus should be testes but the event property must be called for IE, and something different for other browsers... I realized too that event is not present in HTML 4.01, therefore key trapping would take at least too versions of coding to get it compatible with all browsers.
Anyway, post a snippet if you need help