TextBox AutoPostBack=false question (bug?)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a strange yet very simple problem with the asp.net Textbox web control.

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
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
</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 and
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
 
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
 
Yes, i solved it by adding a TextBox with display:none

It's not nice but it works...

Thanks

Renaud
 
Back
Top