Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

Symptoms

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

↑ Back to the top


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.

↑ Back to the top


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>

↑ Back to the top


Status

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

↑ Back to the top


Keywords: KB813822, kbbug

↑ Back to the top

Article Info
Article ID : 813822
Revision : 4
Created on : 4/19/2004
Published on : 4/19/2004
Exists online : False
Views : 401