I'm using VS 2005 to develop an intranet asp.net web application and I get a
weird situation. If I start out with any ASPX page that contains an
ImageButton control followed by a TextBox control, everything works okay. I
can press <ENTER> when the cursor is inside the text box and the page is
running, and no events fire (this is what I expect). But as soon as I drop a
second text box on the page (ie: after th first one) then pressing <ENTER>
in the first text box while running causes the ImageButton1_Click to fire
(even though I'm not actually clicking on the ImageButton control!!!).
I've included a very simple test program below that illustrates the problem.
This is a big problem because I want to have many ImageButton and TextBox
controls on the same ASPX page, and I also do not want the ImageButton Click
event to fire when the user simply presses <ENTER> in a text box. If the
user presses <ENTER> in a text box, or types in data and then presses
<ENTER>, it does the application no good to start firing off Click events
from some unrelated control. In my case it makes my calendar expand out of
nowhere on the page (because the ImageButton control in my case is a "+"
tree expander that is intended to expand or hide the calendar).
What causes this behaviour and how can I fix it?
Thanks,
Tom Edelbrok
Here is the ASPX page (and at the bottom of the post is the Code-Behind VB
stuff):
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Main.aspx.vb"
Inherits="main" %>
<!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">
<div>
<asp:ImageButton ID="ImageButton1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
HERE IS THE CODE-BEHIND VB STUFF:
Partial Class Main
Inherits System.Web.UI.Page
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Response.Write("ImageButton1_Click firing")
End Sub
End Class