Form.DefaultButton behaves incorrectly

T

Tim_Mac

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
 
M

Marina Levit [MVP]

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.
 
T

Tim_Mac

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
 
W

Walter Wang [MSFT]

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/content/content.aspx?ContentID=2220


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================

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

Tim_Mac

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 said:
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/content/content.aspx?ContentID=2220


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================

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

Walter Wang [MSFT]

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 ([email protected], 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.
 
T

Tim_Mac

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top