473,467 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Default Button not working after Validation

Here is the situation:
I have an ASP.NET 2.0 page with 2 panel. Each has a few textboxes and
one DefaultButton. All textboxes have one or more Validator.
Now everything works fine if I fill everything out correctly and then
press the Enter Key, but if the validation fails and I fix the entry
and press enter again, nothing happens anymore.

Someone had the same issue?

Remy

Mar 23 '06 #1
3 3563
Yes, I am having the same problem. Looks like it's back to to the
manual approach until MS releases a fix.

-paul

Apr 1 '06 #2
Ok, I did some poking around and found the problem in the MS
WebResource.axd javascript. To prevent the form from posting multiple
times when an impatient or clumsy user presses enter more than once, MS
sets a flag when the FireDefaultButton function is called. This does
not get reset if the form fails validation, so FireDefaultButton
ignores all subsequent Enter Key presses.

What MS should do in their next hotfix (are you listening?) is set the
__defaultFired flag to true as the last step in the form.onsubmit(), so
that it only prevents the Enter Key press from submitting when it will,
in fact, cause duplicate posts.

Better yet, MS should add a property to the Button controls called
"AllowMultiplePostBacks", defaulted to false. Might be worth doing this
in a custom control in the meantime...

Anyway, there is a workaround. It is a "hack" because the
__defaultFired flag is not intended to be tweaked in client code and
may change in future releases, but it works for now. Keep in mind that
after installing this hack, the form will submit multiple times if the
Enter Key is pressed repeatedly unless you put something in your page
to prevent that.

Put the following code somewhere in the page. Be sure to replace
[DefaultButtonValidationGroup] with the validation group set on your
DefaultButton, or remove that param if you are not using validation
groups.

<script type="text/javascript" language="javascript">
function defaultButtonFix() {
__defaultFired = false;
}
</script>
<asp:CustomValidator ID="cvDefaultButtonFix" runat="server"
ClientValidationFunction="defaultButtonFix"
Display="None"
ValidationGroup="[DefaultButtonValidationGroup]" />

Apr 1 '06 #3
Hey Paul
Thanks a lot for the hint, that was worth a lot and worked nicely, but
after some more digging around I found a second approach that does not
have the repeatedly pressed Enter button problem.
I just "override" the asp.net javascript function and set the
__defaultFired to false if the validation fails.
Its also a pretty big hack, but it seems to work in IE at least.

<script type="text/javascript" language="javascript">
//overwrites the original Page_ClientValidate
function Page_ClientValidate(validationGroup) {
Page_InvalidControlToBeFocused = null;
if (typeof(Page_Validators) == "undefined") {
return true;
}
var i;
for (i = 0; i < Page_Validators.length; i++) {
ValidatorValidate(Page_Validators[i], validationGroup, null);
}
ValidatorUpdateIsValid();
ValidationSummaryOnSubmit(validationGroup);
Page_BlockSubmit = !Page_IsValid;
//this is to correct a little bug in ASP
if(!Page_IsValid)
__defaultFired = false;

return Page_IsValid;
}
</script>

Cheers
Remy Blaettler

Apr 18 '06 #4

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

Similar topics

4
by: Tim Meagher | last post by:
I am trying to use both validation controls and to add submit button attributes, but when I add the button attributes, the javascript fpr the validation controls is no longer created for the page. ...
1
by: Matt Howeson | last post by:
I am sure this question has been asked many times, however I am yet to find a satisfactory solution to the problem. I have a number of user controls within an asp.net page, a login box, a search...
1
by: NancyASAP | last post by:
Thought I'd share this since it took me a long time to get it working. Thanks to a bunch of contributers in Google Groups who shared javascript, etc. The question was: How can I put a reset...
2
by: AnandaSim | last post by:
Hi All, A really puzzling phenomenon. I develop to a Windows 2000 development server in VS 2003. I use Copy Project to deploy the project to a production server. The webpage I'm having...
1
by: Alan Silver | last post by:
Hello, I have just copied a new site up to the production server and have encountered an odd problem. The site uses validation, and this seems to be working fine. For some reason, link button...
1
by: COHENMARVIN | last post by:
I'm working on a project which has a screen with edit fields, and two buttons on the bottom. One button says SAVE and the other button says DELETE. I want to use validators on the fields, but the...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
3
by: Jay | last post by:
I am on the 2.0 framework and have run the c:\windows\microsoft.net \framework\v1.1.4322\aspnet_regiis.exe -c and had no success. About half of the buttons on my webforms are firing and the other...
4
by: SAL | last post by:
Hello, I'm working, basically my first, AJAX page and am having a few problems. One is that the Click event for a button I have in UpdatePanel1 is not getting called. I've tried with the button...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.