BUG: The first enabled Button control receives the RaisePostBack event when the ENTER key is pressed (813822)



The information in this article applies to:

  • Microsoft ASP.NET (included with the .NET Framework 1.1)
  • Microsoft ASP.NET (included with the .NET Framework) 1.0

SYMPTOMS

After a TextBox control handles the RaisePostBack event, the first enabled Button control also receives the RaisePostBack event.

CAUSE

When a Microsoft ASP.NET page has several Button controls, followed by a TextBox control, followed by more Button controls after the TextBox control, when you enter text in the text box and then you press ENTER, the TextBox control receives the RaisePostBack event. The first enabled Button control will always get the RaisePostBack event after the ENTER key has been pressed on the client side even though the ENTER key that is pressed is handled by another control.

WORKAROUND

To work around this problem, insert the following code in your ASP.NET page, and then modify it to fit your particular application requirements.

You cannot call the Page.IsValid property before validation has occured. Query the Page.IsValid property in the event handler for a control when the value of the CausesValidation property is True or after the Page.IsValid method has been called.
<%@ page  %>

<script runat=server language=c#>

public void Page_Load(object s, EventArgs e)
{
	//Validate();
	if (Page.IsValid)
		Response.Write("Valid");
}

</script>

<form runat=server>

<input type=text runat=server id=mytext>
<input type=submit runat=server>

        <asp:RequiredFieldValidator id="RequiredFieldValidator1"
            ControlToValidate="mytext"
            Display="Static"
            InitialValue="" Width="100%" runat=server>
            Fill in a value!
        </asp:RequiredFieldValidator>
</form>

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Modification Type:MajorLast Reviewed:4/19/2004
Keywords:kbBug KB813822 kbAudDeveloper