Solved

Multiple Submit Buttons and validation

Posted on 2004-08-16
9
833 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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, fr…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

813 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

10 Experts available now in Live!

Get 1:1 Help Now