By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,719 Members | 1,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,719 IT Pros & Developers. It's quick & easy.

<ENTER> causes ImageButton to fire! (weird)

P: n/a
I'm using VS 2005 to develop an intranet 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?


Tom Edelbrok

Here is the ASPX page (and at the bottom of the post is the Code-Behind VB

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Main.aspx.vb"
Inherits="main" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="" >

<head runat="server">

<title>Untitled Page</title>



<form id="form1" runat="server">


<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 />






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
May 18 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.