473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Form.DefaultButton behaves incorrectly

this is a re-post of an earlier message. i'm posting it under my MSDN alias
for a better chance of reply :)

when you press return in a multiline textbox, you expect to insert a
newline. However, if you set the Form.DefaultButton property, whatever
javascript code is employed by Asp.Net to handle this functionality
intercepts the key press and submits the form, when using Firefox. This is
a potentially serious problem and certainly a show-stopper for me in terms
of using this very desirable feature. is there an explanation or
work-around?

thanks
tim
Aug 29 '06 #1
7 2775
How would you want it to behave?

I am assuming the javascript code waits for the enter key to be pressed in
any of the input controls, and then submits the form. It doesn't know what
kind of input control it is. And if it did, how would it know the difference
between a 'submit this form' enter and a 'i want a new line' enter.

I've never used it, but sounds like the DefaultButton feature doesn't really
work with the multiline textboxes - at least not in the way you want.

"Tim_Mac" <ti********@community.nospamwrote in message
news:Os**************@TK2MSFTNGP03.phx.gbl...
this is a re-post of an earlier message. i'm posting it under my MSDN
alias for a better chance of reply :)

when you press return in a multiline textbox, you expect to insert a
newline. However, if you set the Form.DefaultButton property, whatever
javascript code is employed by Asp.Net to handle this functionality
intercepts the key press and submits the form, when using Firefox. This
is a potentially serious problem and certainly a show-stopper for me in
terms of using this very desirable feature. is there an explanation or
work-around?

thanks
tim

Aug 29 '06 #2
hi Marina,
thanks for the reply, but with respect, if the DefaultButton feature doesn't
work with multiline textboxes, then it is broke!

obviously when the focus is inside a multiline text-box, pressing return
should insert a blank line. it should never do anything else, especially
submit an incompleted form. surely you would agree that this is a universal
user input standard for the Internet?

most browsers implement form submit behaviour for the return/enter key if
the focus is in any input control (other than textarea). this
enter-key-submit-behaviour causes confusion now that we have more advanced
web forms, e.g. multiple buttons in the same form, and so Asp.Net 2.0 has
introduced a new feature to allow the developer to set the default button
for this behaviour, namely Page.Form.DefaultButton.

the DefaultButton property works correctly in internet explorer. My point
is that the javascript code used by Asp.Net is not compatible with the
vastly popular up-level browser browser: Firefox. If i could spell it out
even more... DefaultButton contains a javascript bug/incompatibility that
causes highly unwanted side-effects in Firefox.

i wouldn't have bothered posting this except that i know the emphasis that
the Asp.Net team placed on compatibility with up-level browsers, and i
thought they would appreciate to be informed of the bug/incompatibility.

tim
Aug 29 '06 #3
Hi Tim,

I understand your concerns about the browser compatibility issues in
ASP.NET 2.0.

For this particular issue, the reason is because javascript generated by
ASP.NET 2.0 has some IE only notation: event.srcElement is not availabe in
FireFox (use event.target instead):

function WebForm_FireDefaultButton(event, target) {
if (!__defaultFired && event.keyCode == 13 && !(event.srcElement &&
(event.srcElement.tagName.toLowerCase() == "textarea"))) {
var defaultButton;
if (__nonMSDOMBrowser) {
defaultButton = document.getElementById(target);
}
else {
defaultButton = document.all[target];
}
if (defaultButton && typeof(defaultButton.click) !=
"undefined") {
__defaultFired = true;
defaultButton.click();
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
return false;
}
}
return true;
}

If we change the first 2 lines into:

function WebForm_FireDefaultButton(event, target) {
var element = event.target || event.srcElement;
if (!__defaultFired && event.keyCode == 13 && !(element &&
(element.tagName.toLowerCase() == "textarea"))) {

Then it will work for both IE and FireFox.

Actually ASP.NET team is already planning to improve browser compatibility
in future version. You can submit your feedback at following site:
http://connect.microsoft.com/Main/co...ContentID=2220
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

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

Aug 30 '06 #4
hi Walter,
thank you very much for a thorough response.
can you point me in the right direction to update the javascript files used
by Asp.Net on my server?
i guess the service pack or future version will be some time away.

thanks again
tim

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:m$**************@TK2MSFTNGXA01.phx.gbl...
Hi Tim,

I understand your concerns about the browser compatibility issues in
ASP.NET 2.0.

For this particular issue, the reason is because javascript generated by
ASP.NET 2.0 has some IE only notation: event.srcElement is not availabe in
FireFox (use event.target instead):

function WebForm_FireDefaultButton(event, target) {
if (!__defaultFired && event.keyCode == 13 && !(event.srcElement &&
(event.srcElement.tagName.toLowerCase() == "textarea"))) {
var defaultButton;
if (__nonMSDOMBrowser) {
defaultButton = document.getElementById(target);
}
else {
defaultButton = document.all[target];
}
if (defaultButton && typeof(defaultButton.click) !=
"undefined") {
__defaultFired = true;
defaultButton.click();
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
return false;
}
}
return true;
}

If we change the first 2 lines into:

function WebForm_FireDefaultButton(event, target) {
var element = event.target || event.srcElement;
if (!__defaultFired && event.keyCode == 13 && !(element &&
(element.tagName.toLowerCase() == "textarea"))) {

Then it will work for both IE and FireFox.

Actually ASP.NET team is already planning to improve browser compatibility
in future version. You can submit your feedback at following site:
http://connect.microsoft.com/Main/co...ContentID=2220
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

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

Aug 30 '06 #5
Hi Tim,

A function in javascript can be redefined; A possible but *NOT* supported
workaround is to put the modified version of the function in a javascript
file and register it in your WebForm:

protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("js1", "JScript.js");
}

For a simplest test page, this works. I'm not sure whether or not it works
for your page. Also, this workaround is dependent on specific version of
ASP.NET since we're using the javascript function from a specific version.
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.

Aug 31 '06 #6
hi Walter,
thanks for the post (and reminder).
i would have liked to find and modify the javascript files used by Asp.Net
2, such as the aspnet_client files in .net 1.1, SmartNav.js and
WebUiValidation.js, but i'm not sure where these exist.

thanks again
tim

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:$u**************@TK2MSFTNGXA01.phx.gbl...
Hi Tim,

A function in javascript can be redefined; A possible but *NOT* supported
workaround is to put the modified version of the function in a javascript
file and register it in your WebForm:

protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("js1", "JScript.js");
}

For a simplest test page, this works. I'm not sure whether or not it works
for your page. Also, this workaround is dependent on specific version of
ASP.NET since we're using the javascript function from a specific version.
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.

Sep 4 '06 #7
Hi Tim,

Thank you for your update.

In ASP.NET 2.0, the resource such as javascript files are embedded in the
assembly. So I'm afraid it's difficult to modify them.

For more information about embedded resource, see following article:

#Handling Client Files in ASP.NET Whidbey
http://msdn2.microsoft.com/en-us/library/ms379629.aspx

Hope this helps. Please feel free to post here if anything is unclear.

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.

Sep 4 '06 #8

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

Similar topics

4
by: Fred Nelson | last post by:
Hi: I'm a relative newby and I'm writing a C# web application in VS2005. I have several forms with multiple buttons. In 95% of the cases users will click a particular button. I would like...
0
by: Tim_Mac | last post by:
i say "bug" in quotes because i can't really blame microsoft for a feature not working in a non-microsoft browser. However, i would have preferred if they did some better browser testing! if i...
3
by: David Lozzi | last post by:
Howdy, I'm using asp.net 2.0 and am trying to get one text box on the page, after the user presses enter, to "click" a specific button. I copied the javascript I used for a .net 1.1 web app I...
3
by: John Mott | last post by:
Hi All, I'm trying to set the defaultbutton for a form to a button contained in a step template for a wizard control. This is the code in PreRender: switch (myWizard.ActiveStep.StepType) {...
3
by: Chinnala | last post by:
All, I have a "Search" button and "Cancel" button on a web page. When I hit enter, the "Cancel" button receives the focus and btnCancel event is fired. But I want the search button event to be...
4
by: Tim Mackey | last post by:
hi, asp.net 2. can anyone explain why this code does not work in firefox (2.0.0.1), but does work in IE 7. if you hit enter after typing something into the textbox, it should fire the Submit...
18
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the 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...
9
by: Veerle | last post by:
Hi, When you use multiple asp:Buttons on one Form, then asp.net generates html submit buttons for all of them. When you put your cursor in one of the textfields of the form, the default submit...
0
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have a MasterPage but on each particular page that uses it, I need to be able to set the DefaultButton for the Form for that page. From the .cs file of my ASPX page, I have tried: -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.