473,549 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.net - Understanding the Postback

I have a problem which I have worked around for some time. I would appreciate
any comments on the following statements.

When the enter key is pressed it causes a postback. After postback code has
been executed, any event driven code is executed. The most common event is
caused by a mouse click of a button. After the enter key has been pressed,
ASP seems to recognize any event and executes the associated code -
regardless of lack of mouse click or the intentions of the user or system
designer.

The most common button causes the entered detail to be validated and saved -
so an accidental Enter key press causes a few messages about required detail
missing. Most people have experienced this - we are left a bit puzzled
because we are still entering detail, but continue doing so.

The situation is made much more difficult if there is more than one button
on the form. The enter key could cause a rediretion or any number of
unexpected actions.
It may be that only one event is recognized - so if the "Save" button is
placed logically first on the firm, its event will be the only one that is
triggered when the enter key is pressed.

It seems to me to be a deficiency in ASP. I tried to overcome the problem by
using HTML buttons and JavaScript events that set flags. Java script will not
recognize a press of the enter key as an event associated with a click of a
button. The difficulty is that the HTML buttons still have to cause a
postback, requiring the Javascript command __dopostback. It worked perfectly
on two of my three forms. I still do not understand why it would not work on
the third form. I appreciate that it has to be associated with a control
which is capable of causing postback, and believe me I tried everything to
get it to work.

So my users have to wake up to themselves. This is the WWW. If they use the
enter key the detail on my form is going to be processed, and if they get
confusing messages or accidently shunt themselves off into cyberspace, that
is not my problem.
Nov 29 '05 #1
8 1632
David,
I have a problem which I have worked around for some time. I would
appreciate
any comments on the following statements.

When the enter key is pressed it causes a postback.


Can you show us how you do this, I have to create a piece of JavaScript to
force this.

Cor
Nov 29 '05 #2
How is possible David that all the events are being executed in the
page???
Only the pageload event and the code for the corresponding button will
be executed at the backend in asp.net.

Nov 29 '05 #3
Below is the HTML from simple form to demonstrate my point. It consists of
three text boxes, a label and a button. Code behind the button click event
will place "Button1 click event code executed" into the Label.
When you enter anything into the first text box, then Press ENTER (DON'T
PRESS TAB, don't enter the remaining text boxes), "Button1 click event code
executed" will appear in the label because the event code has been executed.

I have to create complex forms with many controls and more than one event.
As far as my clients are concerned, it was an accidental enter key press, and
the consequences ridicule the application.

<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="Web Form1.aspx.vb"
Inherits="TestE nterKey.WebForm 1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox></P>
<P>
<asp:TextBox id="TextBox2" runat="server"> </asp:TextBox>
<asp:TextBox id="TextBox3" runat="server"> </asp:TextBox></P>
<P>
<asp:Label id="Label1" runat="server"> Label</asp:Label></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
</form>
</body>
</HTML>

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Label1.Text = "Button1 click event code executed"
End Sub
Thanks for your interest, I appreciate it.
"Cor Ligthert [MVP]" wrote:
David,
I have a problem which I have worked around for some time. I would
appreciate
any comments on the following statements.

When the enter key is pressed it causes a postback.


Can you show us how you do this, I have to create a piece of JavaScript to
force this.

Cor

Nov 29 '05 #4
Yes there is a bit of misleading Phrasing there.
"The enter key could cause a rediretion or any number of unexpected actions.
It may be that only one event is recognized...." . Perhaps you could confirm
that only one event code can be executed. However the point is that a press
of the enter key causes event code to execute, and that enter key action is a
natrual habit of the user.

"vishal" wrote:
How is possible David that all the events are being executed in the
page???
Only the pageload event and the code for the corresponding button will
be executed at the backend in asp.net.

Nov 29 '05 #5
Ok u dont want the textbox2 and textbox3 to be empty.
Then why dont u go with validation controls available in asp.net and
use the code
like
if page.isvalid ....
........
end if

Nov 30 '05 #6
David,

What happens, you can see it yourself, is that if you enter something in the
textbox, the first button gets automaticly focus.

Therefore the Enter will affect that button.

You can try it yourself by adding an extra label and button on your sample.

Cor
Nov 30 '05 #7
Than you Cor. Yes that is the mechanics of the problem. Lets add it to the
definition of the problem. If the Enter Key is pressed, the first button gets
the focus, causing a post back and executing code behind the button. When the
user's Enter key press is "accidental ", the code executed is unexpected and
usually causes confusion.
Vishal, who is also replying to this post, mentions validation controls. An
unexpected postback causes validation controls to display their error
messages. This happens on Microsft's own sites. An innocent Enter key press
after entering one of the first fields causes messages against all required
fields. And it is because the enter key moved the focus to a button which is
able to cause postback.

"Cor Ligthert [MVP]" wrote:
David,

What happens, you can see it yourself, is that if you enter something in the
textbox, the first button gets automaticly focus.

Therefore the Enter will affect that button.

You can try it yourself by adding an extra label and button on your sample.

Cor

Nov 30 '05 #8
You are complaining about a Microsoft standard. You don't have the problem
with PHP.
--
Mad Miss
"David" wrote:
Than you Cor. Yes that is the mechanics of the problem. Lets add it to the
definition of the problem. If the Enter Key is pressed, the first button gets
the focus, causing a post back and executing code behind the button. When the
user's Enter key press is "accidental ", the code executed is unexpected and
usually causes confusion.
Vishal, who is also replying to this post, mentions validation controls. An
unexpected postback causes validation controls to display their error
messages. This happens on Microsft's own sites. An innocent Enter key press
after entering one of the first fields causes messages against all required
fields. And it is because the enter key moved the focus to a button which is
able to cause postback.

"Cor Ligthert [MVP]" wrote:
David,

What happens, you can see it yourself, is that if you enter something in the
textbox, the first button gets automaticly focus.

Therefore the Enter will affect that button.

You can try it yourself by adding an extra label and button on your sample.

Cor

Dec 2 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11096
by: Matthew Louden | last post by:
I want to know if the PostBack concept applies to HTML web-based forms, regardless of what programming technologies we use: For example, ASP, ASP.NET, Java, CGI, etc... PostBack means to send the HTML form to the web server? Since most of the time I heard this term in ASP.NET circle, thats why I raise this question. Please advise. Thanks!
8
11141
by: walesboy | last post by:
greetings - I have a btnSubmit button with a Handles btnSubmit.click which works great if all the user does is click that button. But, if the user ALSO changes a text box on the page (which has it's own event and autopostback=true) before clicking submit then it fires the text box event but never fires the btnSubmit event. (I follow it in...
2
1394
by: rodchar | last post by:
hey all, i have a simple app that references the web.config. i browse to the page. i changed the web.config. i do a postback to the page, And session is gone. Only after i close the browser and reopen it start working with the new settings.
4
3387
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void RaiseCallbackEvent(string eventArgs) { // update the data object with the values currently on screen FormView1.UpdateItem(true); }
2
620
by: Wizzard | last post by:
I have a repeater with and imagebutton on a page useing VS2005 ASP.Net 2.0 <asp:Repeater ID="Repeater1" runat="server" > <ItemTemplate> <div> <asp:ImageButton ImageUrl="button.gif" ID="ImageButton1" runat="server" /> <p><%# Eval("Name") %></p> </div> </ItemTemplate>
11
14796
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be processed by the web server. I am still struggling to understand this postback logic, and hope that some kind gurus out there could help me clarify...
2
2160
by: Nathan Sokalski | last post by:
I have a DataList in which the ItemTemplate contains two Button controls that use EventBubbling. When I click either of them I receive the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- Invalid postback or callback argument. Event validation is enabled...
2
3902
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite well, so at times it is tempting just to port parts of it over mostly as-is. In fact, one MSDN article I read suggested using straight HTML wherever...
9
4537
by: 200dogz | last post by:
Hi guys, I want to have a button which opens up a new window when pressed. <asp:Button ID="Button1" runat="server" Text="Open new window" /> ... Button1.Attributes.Add("OnClick",
0
7548
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7986
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6074
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5391
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3518
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3499
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.