0

In Internet Explorer if I hit enter in the TextBox P it submits the Form using the onclick event of LoginButton.

This is what I want to happen.

In Google Chrome if I hit enter it submits the form with the onclick of Button1.

This is not what I want to happen.

Button1 is actually not visible on the form under normal circumstances. It is made visible under certain circumstances to do a different task then login.

How can I force this, browser independently, to always use LoginButton onclick when someone presses enter?

<asp:TextBox ID="P" runat="server" TextMode="Password" Width="150"></asp:TextBox>
<asp:LinkButton CssClass="button" ID="LoginButton" 
runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1"
onclick="LoginButton_Click" />

<asp:Button 
        ID="Button1" runat="server"
            Text="Submit" onclick="Button1_Click" />       
John Wesley Gordon
  • 910
  • 2
  • 17
  • 39

3 Answers3

2

You set the forms default button:

<form id="Form1"   defaultbutton="SubmitButton"   runat="server">

The Following works for me.

<form id="form1" runat="server" defaultbutton="LoginButton">
<div>
        <asp:TextBox ID="P" runat="server" TextMode="Password" Width="150"></asp:TextBox>
    <asp:LinkButton CssClass="button" ID="LoginButton" 
    runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1"
    OnClick="LoginButton_Click" />

    <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" > </asp:button>   
</div>
</form>
Wombelite
  • 302
  • 1
  • 6
1

You'll probably want to set a default button in your Page_Load method, like this:

this.Form.DefaultButton = this.LoginButton.UniqueID;
Rob Lauer
  • 3,075
  • 1
  • 32
  • 44
  • When I type this in I get an error, does not contain definition for 'LoginButton' and no extension method 'LoginButton' accepting a first argument of 'mynamespace.myclass' could be found. (Are missing a using directive or an assembly reference?) – John Wesley Gordon Nov 18 '13 at 22:01
1

I ended up using C# in my Page_Load(object sender, EventArgs e) method to set the DefaultButton. Found this on another stackoverflow post.

https://stackoverflow.com/a/2213237/2907463

this.Form.DefaultButton = Login1.FindControl("LoginButton").UniqueID;
Community
  • 1
  • 1
John Wesley Gordon
  • 910
  • 2
  • 17
  • 39