BUG: TextBox Controls with the AutoPostBack Property Set to True May Call the TextChanged Event Two Times (828979)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework) 1.0
- Microsoft ASP.NET (included with the .NET Framework 1.1)
SYMPTOMSA TextBox control and a Button control are on a Microsoft ASP.NET Web form and the AutoPostBack event of the TextBox is set to true. When you click the Button control after you type text in the TextBox control, the TextChanged event is triggered two times. You may also notice that the behavior of actions that trigger the TextChanged and the Button_Clicked events is not consistent.WORKAROUNDTo work around this problem, use a script to trap the keypress event and to call the ButtonClick event when the keypress event value is enter. To do this, follow these steps:
- Add the following script block to the <header> section of the WebForm1.aspx code:
<script language="jscript">
function clickButton()
{
if (event.keyCode == 13)
{
myform.Button1.click();
return false;
}
}
</script> - Add the onkeypress event for the TextBox control as follows:
<form id="myform" method="post" runat="server">
<asp:TextBox id="TextBox1" onkeypress="return(clickButton());" ontextchanged="TextBox1_TextChanged" runat="server" AutoPostBack="True"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Clicked" runat="server" Text="Button"></asp:Button>
</form>
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCESFor more information , visit the following Microsoft
Developer Network (MSDN) Web site:
Modification Type: | Major | Last Reviewed: | 10/6/2003 |
---|
Keywords: | kbpending kbServerControls kbScript kbWebForms kbbug KB828979 kbAudDeveloper |
---|
|