473,657 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP: [RETURN] key is not submitting form (ASP.NET 2.0)

Hi,

trying to submit an ASPX form using the [RETURN] key (using IE6) the page is not submitted in my web project.

Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client script code being executed having a flaw:

function anonymous() {
if (!ValidatedText BoxOnKeyPress(e vent)) { event.cancelBub ble = true; if (event.stopProp agation) event.stopPropa gation(); return false; }
}

In this code, not all paths return a value! So my guess is that a random value is used by IE to consider whether to submit the form.

If this is true then I guess there's a bug in ASP.NET blocking me from implementing my customer's requirements.

Any ideas?

TIA,
Axel Dahmen

Feb 20 '07 #1
18 5790
there is nothing wrong with the code. it returns void if no validtion is
required or validation is ok, or false if validation fails (and also as
a hack for an ie 6 bug in event canceling), which is what the browser wants.

if you look asp.net has default button support (which button to fire on
enter). see panel control.

-- bruce (sqlwork.com)

Axel Dahmen wrote:
Hi,

trying to submit an ASPX form using the [RETURN] key (using IE6) the page is not submitted in my web project.

Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client script code being executed having a flaw:

function anonymous() {
if (!ValidatedText BoxOnKeyPress(e vent)) { event.cancelBub ble = true; if (event.stopProp agation) event.stopPropa gation(); return false; }
}

In this code, not all paths return a value! So my guess is that a random value is used by IE to consider whether to submit the form.

If this is true then I guess there's a bug in ASP.NET blocking me from implementing my customer's requirements.

Any ideas?

TIA,
Axel Dahmen
Feb 20 '07 #2
I see... Didn't know void was a legal return value.

It seems the script debugger doesn't step through dynamically generated code (new Function(){...} ). In that case I now know where to search now...

Thanks, Bruce!

Regards,
Axel

-----------
"bruce barker" <no****@nospam. comschrieb im Newsbeitrag news:OQ******** ******@TK2MSFTN GP04.phx.gbl...
there is nothing wrong with the code. it returns void if no validtion is
required or validation is ok, or false if validation fails (and also as
a hack for an ie 6 bug in event canceling), which is what the browser wants.

if you look asp.net has default button support (which button to fire on
enter). see panel control.

-- bruce (sqlwork.com)

Axel Dahmen wrote:
Hi,

trying to submit an ASPX form using the [RETURN] key (using IE6) the page is not submitted in my web project.

Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client script code being executed having a flaw:

function anonymous() {
if (!ValidatedText BoxOnKeyPress(e vent)) { event.cancelBub ble = true; if (event.stopProp agation) event.stopPropa gation(); return false; }
}

In this code, not all paths return a value! So my guess is that a random value is used by IE to consider whether to submit the form.

If this is true then I guess there's a bug in ASP.NET blocking me from implementing my customer's requirements.

Any ideas?

TIA,
Axel Dahmen
Feb 20 '07 #3
Hi Alex,

Both the HtmlForm and the Panel have a property named DefaultButton could
let you assign a default button when ENTER key is pressed:

<form id="form1" defaultbutton=" Button1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:TextBox ID="TextBox3" runat="server"> </asp:TextBox>
<asp:Panel ID="Panel1" DefaultButton=" Button2" runat="server"
Height="50px" Width="125px">
<asp:Button ID="Button2" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:TextBox ID="TextBox2"
runat="server"> </asp:TextBox></asp:Panel>

</div>
<asp:Panel ID="Panel2" DefaultButton=" Button3" runat="server"
Height="50px" Width="125px">
<asp:Button ID="Button3" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:TextBox ID="TextBox1"
runat="server"> </asp:TextBox></asp:Panel>
</form>

protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Write( (sender as Button).ID);
}

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 21 '07 #4
Hi Walter,

great to hear from you! I guess the DefaultButton property doesn't work for LinkButtons, does it? Our website uses LinkButtons exclusively. We're applying the company's style guide to them.

I've created a function to scan Request.Form["__EVENTTAR GET"] for not being any of a page's link buttons on post back. This code raises a DefaultButtonPr essed event appropriately.

Yet, unfortunately the form doesn't post back at all when I press the [RETURN] key at the moment... I've created a second function to inject code into the document.forms[0].onsubmit event handler. Perhaps the code I'm injecting there doesn't work properly... I needed to write custom code since Page.ClientScri pt.RegisterOnSu bmitStatement injects code before validation but we want to get code executed *after* validation has been performed successfully. Perhaps you've got an idea?

Best regards,
www.dashop.de
Axel Dahmen
--------------
"Walter Wang [MSFT]" <wa****@online. microsoft.comsc hrieb im Newsbeitrag news:JY******** *****@TK2MSFTNG HUB02.phx.gbl.. .
Hi Alex,

Both the HtmlForm and the Panel have a property named DefaultButton could
let you assign a default button when ENTER key is pressed:

<form id="form1" defaultbutton=" Button1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:TextBox ID="TextBox3" runat="server"> </asp:TextBox>
<asp:Panel ID="Panel1" DefaultButton=" Button2" runat="server"
Height="50px" Width="125px">
<asp:Button ID="Button2" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:TextBox ID="TextBox2"
runat="server"> </asp:TextBox></asp:Panel>

</div>
<asp:Panel ID="Panel2" DefaultButton=" Button3" runat="server"
Height="50px" Width="125px">
<asp:Button ID="Button3" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:TextBox ID="TextBox1"
runat="server"> </asp:TextBox></asp:Panel>
</form>

protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Write( (sender as Button).ID);
}

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 21 '07 #5
Hi Axel,

Thanks for the update.

For the first part about LinkButton, based on my test, if the form has a
defaultButton set, focus on a LinkButton and press ENTER will still make
the defaultButton to submit the form. Also, if you set the defaultButton
attribute of the form to a LinkButton, it also works. I'm not sure if I
fully understood your question here, would you please elaborate more?

For the second part of the question, do you mean that you want to execute
some custom javascript code after the page's client-side validation passes?
I'm afraid it will not be easy to do so. Let's take a look at the
javascript generated by ASP.NET (view the webform in IE and save it as a
complete static html page to get the javascript files):

function WebForm_PostBac kOptions(eventT arget, eventArgument, validation,
validationGroup , actionUrl, trackFocus, clientSubmit) {
this.eventTarge t = eventTarget;
this.eventArgum ent = eventArgument;
this.validation = validation;
this.validation Group = validationGroup ;
this.actionUrl = actionUrl;
this.trackFocus = trackFocus;
this.clientSubm it = clientSubmit;
}
function WebForm_DoPostB ackWithOptions( options) {
var validationResul t = true;
if (options.valida tion) {
if (typeof(Page_Cl ientValidate) == 'function') {
validationResul t = Page_ClientVali date(options.va lidationGroup);
}
}
if (validationResu lt) {
if ((typeof(option s.actionUrl) != "undefined" ) &&
(options.action Url != null) && (options.action Url.length 0)) {
theForm.action = options.actionU rl;
}
if (options.trackF ocus) {
var lastFocus = theForm.element s["__LASTFOCU S"];
if ((typeof(lastFo cus) != "undefined" ) && (lastFocus != null)) {
if (typeof(documen t.activeElement ) == "undefined" ) {
lastFocus.value = options.eventTa rget;
}
else {
var active = document.active Element;
if ((typeof(active ) != "undefined" ) && (active !=
null)) {
if ((typeof(active .id) != "undefined" ) &&
(active.id != null) && (active.id.leng th 0)) {
lastFocus.value = active.id;
}
else if (typeof(active. name) != "undefined" ) {
lastFocus.value = active.name;
}
}
}
}
}
}
if (options.client Submit) {
__doPostBack(op tions.eventTarg et, options.eventAr gument);
}
}

<A
id=LinkButton1
href='javascrip t:WebForm_DoPos tBackWithOption s(new
WebForm_PostBac kOptions("LinkB utton1", "", true, "", "", false,
true))'>LinkBut ton</A>
As you can see, the validation and the postback steps are currently
executed in a single javascript function WebForm_DoPostB ackWithOptions. You
might want to replace the __doPostBack function to do your own stuff but I
haven't tested this. The default __doPostBack implementation is generated
in the webform as:

<SCRIPT type=text/javascript>
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(ev entTarget, eventArgument) {
if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
theForm.__EVENT TARGET.value = eventTarget;
theForm.__EVENT ARGUMENT.value = eventArgument;
theForm.submit( );
}
}
// -->
</SCRIPT>
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 22 '07 #6
Hi Axel,

Please ignore second part of my last reply since I've got some updated
information.

To execute some javascript before submitting the form and after the
client-side validation succeeds, you simply call some javascript in form's
onsubmit handler:

#Followers of the IHttpHandler : No more hijacking of __doPostBack in
Whidbey
http://weblogs.asp.net/vga/archive/2...fDoPostBackInW
hidbey.aspx

#onsubmit Event (FORM)
http://msdn2.microsoft.com/en-us/library/ms536972.aspx
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 23 '07 #7
Hi Walter,

thank you for your reply. I'll try to use DefaultButton in our forms 'till
end of the week. Can't tell if it works for us right now although I'm rather
optimistic that it'll work.

The other solution, though, doesn't work for me as we're already using
Whidbey. The problem with the Page.RegisterOn SubmitStatement () member
function is that it inserts code *before* validators are executed. Yet, I
need to execute some code *after* validators have (successfully) executed
because I need to show a "please wait..." <divelement.
This is what Page.RegisterOn SubmitStatement () does (basically):

form.onsubmit()
{
-- RegisterOnSubmi tStatement inserts code here --
if (!PageIsValid() ) return false;
return true;
}
yet, what I need is:

form.onsubmit()
{
if (!PageIsValid() ) return false;
-- insert code here --
return true;
}
Currently I'm injecting this code manually using regular expressions and
creating a new Form object having my code inserted at the right place.
Unfortunately I can't debug into the so created function code.

Do you know any other way to have code inserted where I need it? Or would
this be something to suggest to the VS team?

TIA,
Axel Dahmen

PS.: Please remember I can't reply to your posts from my customer's office.
They have blocked the news: protocol back in Frankfurt.
----------------
"Walter Wang [MSFT]" <wa****@online. microsoft.comsc hrieb im Newsbeitrag
news:Uq******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Axel,

Please ignore second part of my last reply since I've got some updated
information.

To execute some javascript before submitting the form and after the
client-side validation succeeds, you simply call some javascript in form's
onsubmit handler:

#Followers of the IHttpHandler : No more hijacking of __doPostBack in
Whidbey
http://weblogs.asp.net/vga/archive/2...fDoPostBackInW
hidbey.aspx

#onsubmit Event (FORM)
http://msdn2.microsoft.com/en-us/library/ms536972.aspx
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.
>

Feb 27 '07 #8
Hi Axel,

To achieve your objective here (only execute some code after the page is
validated at client-side), don't use RegisterOnSubmi tStatement here (by the
way, Page.RegisterOn SubmitStatement is obsolete now in .NET 2.0, try to use
ClientScriptMan ager.RegisterOn SubmitStatement instead).
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

protected void Page_Load(objec t sender, EventArgs e)
{
// ClientScript.Re gisterOnSubmitS tatement(this.G etType(), "submit",
"return confirm('Contin ue?')");
form1.Attribute s.Add("onsubmit ", "return confirm('Contin ue?')");
}

protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Write( "Button1_Click" );
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ControlToValida te="TextBox1"

ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button 1_Click" /></div>
</form>
</body>
</html>
Using above test webform, the confirmation prompt will only display when
the client-side validation passed.

Let me know if this is what you want.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 1 '07 #9
Hi Walter,

thanks a lot for the response you've mailed to me. Your reply has put me on
the right path and it's helping me a lot indeed in finding the problem.

In your solution you wrote that there's an (apparently) invisible validator
keeping the page from submitting. I'll try to debug the .html pages to see
which validator that is. Perhaps some CSS is keeping the validator from
showing up.

Currently I don't see how I can possibly debug through the JavaScript that's
generated by the .axd files. Is there a way to debug through this code so I
can find the problem without first exporting the page into HTML using FireFox
(since IE doesn't do this)?

Walter, I really appreciate the effort you've already put into solving our
problem. Thanks a lot!

TIA,
Axel
--------------------------------
"Walter Wang [MSFT]" wrote:
Hi Axel,

To achieve your objective here (only execute some code after the page is
validated at client-side), don't use RegisterOnSubmi tStatement here (by the
way, Page.RegisterOn SubmitStatement is obsolete now in .NET 2.0, try to use
ClientScriptMan ager.RegisterOn SubmitStatement instead).
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

protected void Page_Load(objec t sender, EventArgs e)
{
// ClientScript.Re gisterOnSubmitS tatement(this.G etType(), "submit",
"return confirm('Contin ue?')");
form1.Attribute s.Add("onsubmit ", "return confirm('Contin ue?')");
}

protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Write( "Button1_Click" );
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ControlToValida te="TextBox1"

ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button 1_Click" /></div>
</form>
</body>
</html>
Using above test webform, the confirmation prompt will only display when
the client-side validation passed.

Let me know if this is what you want.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 28 '07 #10

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

Similar topics

1
14952
by: Jason | last post by:
I've got a standard form on an ASP page to collect resumes from visitors. The page can be accessed only after the visitor has logged into the site. The issue that I'm running into is that the users are exceeding the length of the session timeout, so when they submit the form, it is taking them back to the login page instead of submitting the form. The solution I am trying (extending timeout session is not an option due to the heavy load...
7
3594
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
4
2287
by: Rick | last post by:
Hello, I'm having trouble with submitting my form when checking to see if data is present in the user-inputted fields. What I want to happen is for the user to input various pieces of data, submit the form, and then have a javascript function that checks to see if data is entered, and if not, have an alert window tell the user which field to enter data into and then revert back to that same page. If all data is entered, it would...
2
1844
by: Jackal | last post by:
I have a form page(abc.aspx) that contains some fields need to be filled in before submitting, and the action of the form is "def.aspx". After peocessing the filled-in data, it'll return the result. Is there any chance I could get the result by programming? Fill in data on "abc.aspx" --> Submit --> "def.aspx" requests the data --> Processing --> Returns the result to "abc.aspx"
3
6179
by: hermand | last post by:
I've got an online job application I am building using ASP/VBScript. The application consists of one ASP document which has three separate states. States: 1. Form Display 2. Form Review (takes all information submitted from the first form state and removes the form elements and displays entered information using "Response.form()".
8
1332
by: greg.gottfried | last post by:
I am very new to java script. I am wanting to validate a form and I cant seem to get one validation to work. The first two work, but the thrid I want to have a max length of 30 and I cant ssem to figure out how to do that. Please help! var msg = ""; if(document.jobOpening.jobCity.value == ""){ msg = msg + "Please provide a Job City before submitting the form."; alert(msg); document.jobOpening.jobCity.focus();
17
2078
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms created and working. The first form the user fills out and submits. The form properties are set to Send to other: "Custom ISAPI, NSAPI, CGI, OR ASP SCRIPTING. The method is "POST" and the action is "secondpage.asp". I had to go this route because...
1
1612
by: asp beginner | last post by:
I am building an Eccomerce site and I am trying to make my shopping cart work. I am having a problem with when I have entered data into my form it is not submitting into my access database. This my coding for my page. I am very new at all this and any help with be most appreciated. <%@ Page Language="vb" Debug="True"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Drawing" %>...
0
8382
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6162
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1930
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.