Fred
Fred

Reputation: 5808

Required Field conditional on button pressed

I may be having a blonde moment here.

I have a data entry form with the usual "Save" and "Cancel" buttons. In addition to these two I have another button "Approve". If the user clicks the "Approve" button I have an additional field (Approver) that must hold data. Is it possible to have a required field validator that is active on one button press but not another?

Upvotes: 0

Views: 121

Answers (2)

Anass
Anass

Reputation: 974

Yes This is possible : You can Define multiple Validation group and decide witch group to validate depending on the clicked button, for that you should call javascript function onClientClient in order to validate the inputs :

See example bellow:

Triggering multiple validation groups with a single button

Upvotes: 1

Ted
Ted

Reputation: 4067

I think you will have to create a custom validator or just use javascript or jquery.

You can use the OnClientClick property of the buttons and add some javascript on there.

function CheckSave() {
  if (/*text1 is filled*/) return true;
}

function CheckApprove() {
  if (/*text1 is filled and text2 is filled*/) return true;
}

<asp:button id='btnSave' OnClientClick='return CheckSave()' OnClick='btnSave_Click' />    
<asp:button id='btnApprove' OnClientClick='return CheckApprove()' OnClick='btnAprove_Click' />

you need the return in order for it to work

Upvotes: 0

Related Questions