Panel default buttons not working in IE RRS feed

  • Question

  • User907408599 posted

    I've created a simple page to demonstrate this:


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

    <!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>Test Page</title>
    <meta name="ROBOTS" content="NOINDEX" />
    <form id="form1" runat="server">
    <asp:Panel ID="Panel1" DefaultButton="Button1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    <asp:Panel ID="Panel2" DefaultButton="Button2" runat="server">
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


    using System;

    public partial class test : System.Web.UI.Page

    protected void Button1_Click(object sender, EventArgs e) {
    Label1.Text = TextBox1.Text;
    protected void Button2_Click(object sender, EventArgs e) {
    Label1.Text = TextBox2.Text;

    This works as intended in Firefox 3.5. However in IE 8, hitting return will always fire Button1_Click - even if TextBox2 has focus. Any idea how to fix it?

    Thanks Smile

    Saturday, July 4, 2009 4:59 PM

All replies

  • User1945764768 posted

    everything seems to be working fine in ie8 . I re wrote in vb and everything seems ok

    Simple page

    Saturday, July 4, 2009 9:01 PM
  • User907408599 posted

    Thanks for your reply. It seems that your page doesn't work in FF or IE (for me..). The point is that by grouping the controls into two Panels, different buttons should be clicked when you press the Enter key, depending on where the focus is.

    Panel1[DefaultButton="Button1"] { TextBox1, Button1 }

    Panel2[DefaultButton="Button2"] { TextBox2, Button2 }


    So if you press the enter key in TextBox2, it should have the effect of Button2 being clicked. Can anyone else reproduce this problem or is it just me?

    Sunday, July 5, 2009 8:16 AM
  • User1945764768 posted

    I am sorry I miss understood you can guarantee that if textbox2 focus then button 2 focus but you have to press enter twice

    protected void TextBox2_TextChanged(object sender, System.EventArgs e)

    not the exact answer sorry would like to know the answer if you work out
    Sunday, July 5, 2009 9:38 AM
  • User1945764768 posted

    if  added in

    protected void textbox2_PreRender(object sender, System.EventArgs e)




    it moves from button1 to button 2

    you can also add button2.focus in button click so if you had 10 textboxes and ten buttons

    then button3 click button4.focus only works if textbox already has text

    Sunday, July 5, 2009 11:41 AM
  • User907408599 posted

    You've lost me.

    We can't set focus while I'm still typing in the textbox because then the textbox would lose focus. There ought to be a simple solution using the Panel.DefaultButton property (which Microsoft obviously intended us to use).

    Sunday, July 5, 2009 12:02 PM
  • User1945764768 posted

    I think this might help

    DefaultButton property

    Sunday, July 5, 2009 12:26 PM
  • User-1675817941 posted


    See button behavoir is like that, button is sumbit while click/pressing enter key it will triggred.

    if you want to avoid this use html control.

    <input type="button" id="btnSave" value="Save" runat="server"/>

    Thanks :)



    Sunday, July 5, 2009 2:51 PM
  • User1459534743 posted


    Sunday, July 5, 2009 6:07 PM
  • User604186779 posted

    This works as intended in Firefox 3.5. However in IE 8, hitting return will always fire Button1_Click - even if TextBox2 has focus. Any idea how to fix it?

    could you check this


    Monday, July 6, 2009 12:39 AM
  • Monday, July 6, 2009 2:15 AM
  • User-925286913 posted

    Set  UseSubmitBehavior="false" :

    <asp:Button ID="btnTest" runat="server" UseSubmitBehavior="false" />

    Monday, July 6, 2009 2:22 AM
  • User907408599 posted

    Set  UseSubmitBehavior="false" :

    <asp:Button ID="btnTest" runat="server" UseSubmitBehavior="false" />

    This makes no change in Firefox (ie. still works), but now in IE pressing Enter in either textbox does nothing. IE8 also says 'Page has errors' in the bottom-left, check it out.

    Monday, July 6, 2009 10:35 AM