Solved

Multiple Submit Buttons and validation

Posted on 2004-08-16
9
831 Views
Last Modified: 2008-09-10
Hello,
I have a problem which is driving me nuts.
i have 3 submit buttoms on my webform which are  have their own validation control and ValidationSummary. The problem arises when i click on any of these buttons, the validation of other 2 buttons will run at the same time.

Is there any way to solve this problem. I tried setting enabled=false in the validationFields and try to enable them in code behind file by having:
    Private Sub activeButton_click(ByVal sender As System.Object, ByVal e As EventArgs) Handles activeButton.Click

        validationTest.enabled=true

    End Sub
now the user have to click twice on button to validate

thx in advance
0
Comment
Question by:roddios
9 Comments
 
LVL 8

Expert Comment

by:daffodils
ID: 11815769
Here is another option,
In the click event of one button you can set the "CausesValidation" for the other two buttons to false.

That would stop the validation for the other two buttons from firing and you don't have to click button 1 twice.

Private Sub activeButton_click(ByVal sender As System.Object, ByVal e As EventArgs) Handles activeButton.Click

        button2.Causesvalidation=false
        button3.Causesvalidation=false

End Sub

0
 
LVL 8

Expert Comment

by:daffodils
ID: 11815784
That is "Causesvalidation".. I guess VB is not case-sensitive.. just in case

        button2.CausesValidation=false
        button3.CausesValidation=false
0
 

Author Comment

by:roddios
ID: 11816173
thx for your solution daffodils
i tried CausesValidation=false but i still get all validations execute at the same time. i tried the reverse having initially all buttons CausesValidation=false then in code behind file i change button1.CausesValidation=true. Still have the same weird problem having buttons clicked twice to work!
would getting rid of validateSummary help ?
0
 
LVL 8

Expert Comment

by:daffodils
ID: 11816361
Hi there..
I get your problem now.. yeah setting the CausesValidation is not going to help. The validation will be still performed.

>> would getting rid of validateSummary help
Nopes that is not going to help either.. the problem is that ASP.NET Validation occurs during Page_Load and the Click event is the last event to be fired.
The sequence of events is Page_Load -->Cached Events (textchanged etc if defined) --> Postback (like Click etc)
So by the time we set or reset any value in Click event, the validation has already been performed. So it will be displayed no matter what.

What we can do is set Enabled=true by default for all validation controls.. and then in the Page_Load.. check if the click is from Button 1 or 2 or 3 and selectively set the Enabled=false for the validation controls. Then depending upon the button clicked, the respective error messages would be displayed in the validation control and the summary.

pretty complicated huh.. let me see.. will get back to you.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Accepted Solution

by:
daffodils earned 125 total points
ID: 11816403
wait .. I mixed things up there.. junk that!  

>> would getting rid of validateSummary help
Nopes that is not going to help either.. the problem is that ASP.NET Validation occurs during Page_Load and the Click event is the last event to be fired.
The sequence of events is Page_Load -->Cached Events (textchanged etc if defined) --> Postback (like Click etc)

NEW ADD--> And if validation fails the form is never posted back !! So if the validation fails, the CLick event NEVER fires.. so setting or unsetting any value there is not going to make a difference !

What we can do is set Enabled=true by default for all validation controls..

NEW ADD--> We would probably ahve to write a javascript function and check if the click is from Button 1 or 2 or 3 and selectively set the Enabled=false for the validation controls.
Then depending upon the button clicked, the respective error messages would be displayed in the validation control and the summary.
0
 
LVL 8

Expert Comment

by:daffodils
ID: 11816409
call this javascript function from the onClick event of the Button
and set the Enabled property values in that function.
0
 
LVL 11

Expert Comment

by:saleek
ID: 11818850
Hi,

Don't quite understand your problem but....

The other 2 buttons are they firing a RequiredFieldValidator or something similar (regular expression validator)??

If so, asl well as setting CausesValidation to false on the buttons, you can also set the visibility of the validation controls to false, which will stop them firing.

regards,

KS
0
 

Author Comment

by:roddios
ID: 11881146
thank you for your replies.
i kinda gave up on this and check them server side
0
 
LVL 1

Expert Comment

by:Emanuele_Ciriachi
ID: 22436547
Well if you are lucky enough to use .Net 2.0 by now (more than 4 years later), the solution is piece of cake.
Just use ValidationGroup property value to (all the input controls, the validator control and the button in) one section of the page and another unique ValidationGroup property value for the other section and it should perform your required operation with ease.

<asp:TextBox id="txtId" ValidationGroup="findbyid" Runat="server"></asp:TextBox>
<asp:Button id="btnId" ValidationGroup="findbyid" Runat="server" Text="Find"></asp:Button>
<asp:RegularExpressionValidator Runat="server" ID="rxvId" ValidationGroup="findbyid"
   ControlToValidate="txtId" ErrorMessage="* Invalid" ValidationExpression="^\d+$">
   </asp:RegularExpressionValidator>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now