Solved

Multiple Submit Buttons and validation

Posted on 2004-08-16
9
829 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

22 Experts available now in Live!

Get 1:1 Help Now