Click to See Complete Forum and Search --> : Requiredfieldvalidators firing before Customvalidators


invisible kid
04-16-2006, 08:08 AM
Hi guys,

I have a load of requiredfield validators on a form, e.g.

<asp:RequiredFieldValidator id="RequiredFieldValidator1" ControlToValidate="txtFirstName" ErrorMessage="*Please fill in" Runat="server"></asp:RequiredFieldValidator>

I also have customfield validators on the same page, e.g.

<asp:CustomValidator id="CustomValidator6" runat="server" ErrorMessage="*Please select" ControlToValidate="cbo1stVisaType" OnServerValidate="CustomValidator6_ServerValidate"></asp:CustomValidator>

With the backend code...

protected void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid=(cboReason.SelectedValue!="None");
}

However, when ever the requiredfieldvalidators fire, this stops the customvalidators from firing.

I cannot get them to both fire at the same time.

Please can anyone help?

handshakeit
04-17-2006, 12:19 AM
why don't u try required field validation at the client side and other custom field validator on the server
change clientsidevalidation property of required field validator true

invisible kid
04-17-2006, 04:30 AM
why don't u try required field validation at the client side and other custom field validator on the server
change clientsidevalidation property of required field validator true

There is no such property as clientsidevalidation.

I've tried setting "EnableClientScript=true" for all req. field validators but this didn't help.

handshakeit
04-18-2006, 12:31 AM
However, when ever the requiredfieldvalidators fire, this stops the customvalidators from firing.
It is due to required field validator is fired at the clientside and custom field validator will fire on server

If u want both to fire on server side do
EnableClientScript=false

hytechpro
04-18-2006, 12:38 AM
Hi

If you want to fire both validation at same time either set both at clientside
or both at server side
But prefer to use all validation on client side if possible
ie. doesn't require any server resource

Thanxs
Dev

invisible kid
04-18-2006, 04:40 PM
Thanks guys, this worked a treat.

invisible kid
04-18-2006, 06:41 PM
Actually, now I have just set all my validators to run client-side, I've run into another problem!

When there are errors, I also want to display a summary message at the bottom of the page saying e.g. "You have not field in all the fields correctly".

So, I tried to do this inside my button-click method. However, it seems like the client-side validators are firing first and stopping anything within my button-click method actually firing!

Is there a way round this or will I have to go back to all server-side validation?

handshakeit
04-19-2006, 12:24 AM
use validationsummary control to show all errors combined
and place it at the bottom of ur page

I searched to google abou ur problem
read this hope this will help u
http://msdn.microsoft.com/msdnmag/issues/02/04/Valid/

invisible kid
04-20-2006, 02:39 AM
use validationsummary control to show all errors combined
and place it at the bottom of ur page

I searched to google abou ur problem
read this hope this will help u
http://msdn.microsoft.com/msdnmag/issues/02/04/Valid/

Validationsummary works great, thanks.

However, I also want to set a viewstate variable when the user clicks the submit button, so we can keep track of whether to fire validation on autpostback (see this thread: http://www.webdeveloper.com/forum/showthread.php?t=103240).

At present, from what I can tell, my client-side validators are firing and stopping anything within the button-click method from happening.

Should I still switch to server-side only validation? Or is there a way round this?

e.g.

private void Button1_Click(object sender, System.EventArgs e)
{
ViewState["formSubmitted"] = "1";
}

protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Panel1.Visible = true;

formSub = (string)ViewState["formSubmitted"];

if (formSub != null)
{
this.Validate();
}
}

handshakeit
04-20-2006, 03:15 AM
I can not understand the problem
if there is error then the all action will be cancelled
and will work if there is no error
is it not so
If u want to proceed with errors then what is the use of validators?????