Question

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" />       
Was it helpful?

Solution 3

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;

OTHER TIPS

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>

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

this.Form.DefaultButton = this.LoginButton.UniqueID;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top