Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple Submit Buttons and validation

Posted on 2004-08-16
9
Medium Priority
?
849 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 500 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:Ramesh Srinivas
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 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