Solved

Multiple Submit Buttons and validation

Posted on 2004-08-16
9
839 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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