Tuesday, March 13, 2012

TextBox AutoPostBack=false question (bug?)

Hello,
I have a strange yet very simple problem with the asp.net Textbox web contro
l.
On an empty asp.net page, add a single asp:TextBox control with
Autopostback=false with nothing else on the page.
according to the doc, hitting Enter while the TextBox has focus should do
nothing since Autopostback=false. The problem i have is that it posts the
form (that is, it ignores the Autopostback=false).
Now if i add another textbox to the page, i no longer experience the
problem(''?).
Is my framework (2.0) corrupted or is anyone else able to reproduce that bug
?
Thanks for any help
Renaud
=============
sample page
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txt" AutoPostBack="false"
></asp:TextBox>
</form>
</body>
</html>Apparently this is the default behavior of an ASP.NET page with only one
textbox on it. For example if there were a page that had a search textbox an
d
no button to submit the search, you could type in a search term and hit the
ENTER key and the form would be submitted.
There are lots of techniques and new features in ASP.NET 2.0 that let you
customize this type of behavior, such as the "defaultbutton" property of the
FORM element.
But the bottom line is, there's nothing wrong with your Framework - that's
just "the way it is".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Renaud Langis" wrote:

> Hello,
> I have a strange yet very simple problem with the asp.net Textbox web cont
rol.
> On an empty asp.net page, add a single asp:TextBox control with
> Autopostback=false with nothing else on the page.
> according to the doc, hitting Enter while the TextBox has focus should do
> nothing since Autopostback=false. The problem i have is that it posts the
> form (that is, it ignores the Autopostback=false).
> Now if i add another textbox to the page, i no longer experience the
> problem(''?).
> Is my framework (2.0) corrupted or is anyone else able to reproduce that b
ug?
> Thanks for any help
> Renaud
> =============
> sample page
> <%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
> Inherits="_Default" %>
> <html>
> <body>
> <form id="form1" runat="server">
> <asp:TextBox runat="server" ID="txt" AutoPostBack="false"
> </form>
> </body>
> </html>
The main problem with this behavior is that it bypasses the control
validations.
If the textbox is a TextBoxValidator, hitting the enter key posts the form
even if the textbox content breaks the validation rules. Validations are
performed correctly on the server side but it's still a useless roundtrip to
the server.
I suppose this could be corrected by using a button on the page. The problem
is, in our application, buttons are replaced by LinkButtons.
Thanks for your quick answer.
Renaud
"Peter Bromberg [C# MVP]" wrote:
> Apparently this is the default behavior of an ASP.NET page with only one
> textbox on it. For example if there were a page that had a search textbox
and
> no button to submit the search, you could type in a search term and hit th
e
> ENTER key and the form would be submitted.
> There are lots of techniques and new features in ASP.NET 2.0 that let you
> customize this type of behavior, such as the "defaultbutton" property of t
he
> FORM element.
> But the bottom line is, there's nothing wrong with your Framework - that's
> just "the way it is".
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
> "Renaud Langis" wrote:
>
Have you tried something like adding another Textbox to your page, and
setting its width property to zero?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Renaud Langis" wrote:
> The main problem with this behavior is that it bypasses the control
> validations.
> If the textbox is a TextBoxValidator, hitting the enter key posts the form
> even if the textbox content breaks the validation rules. Validations are
> performed correctly on the server side but it's still a useless roundtrip
to
> the server.
> I suppose this could be corrected by using a button on the page. The probl
em
> is, in our application, buttons are replaced by LinkButtons.
> Thanks for your quick answer.
> Renaud
> "Peter Bromberg [C# MVP]" wrote:
>
Yes, i solved it by adding a TextBox with display:none
It's not nice but it works...
Thanks
Renaud
"Peter Bromberg [C# MVP]" wrote:
> Have you tried something like adding another Textbox to your page, and
> setting its width property to zero?
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
> "Renaud Langis" wrote:
>

0 comments:

Post a Comment