Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RequiredFieldValidator question

Status
Not open for further replies.

flnMichael

Programmer
Nov 13, 2003
96
US
Hey,
I have a page with about 5 text fields being validated with RequiredFieldValidators. Once I hit the submit button, I have the IsPostback portion disabling the Validators...Is that even right? Anyway, When the submit button is pressed once the page is reloaded, the code behind enables the validators again, but that doesn't seem to function right...Can anyone help?

Thanks
Mike
 
You don't need to do anything with the RequiredFieldValidators on the server side. They operate on the client-side to make sure the user has entered details in your controls. If they have then it lets them click the button and will submit the form otherwise the form will not be submitted.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
ok, I have another situation...
I have a datagrid with the edit, update, and delete buttons. I also have an area where I can add to the datagrid. These are seperate from eachother, but the validators will validate the add area when I hit any of the edit, update, or delete buttons. I have two scenarios:

1. I have the validators disabled on page load, but on the first round of adding a row, the validators don't work. I have the validator.enabled = true in the add button function right at the top, but it still goes through the whole function before it actuallly enables them.

2. I enable validators on page load. If I go to the edit button, I get validated. I disable the validators in the edit function, but like the 1st scenario, it runs through the function before it disables them.

Is there a third scenario I'm missing???

Thanks
Mike
 
So the fields that you wish to validate are only required in some cases? If so then i would suggest not using the RequiredFieldValidator as this will be called in all cases - you could just use a CustomValidator instead and do the validation server side instead.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
works great, thanks.

Now I know I should ask this in another thread, but it's a small question. How can I get the row count of a returned query?

Thanks again
Mike
 
You will find that you open most queries in a forward only mode so you can't actually find out how many rows are returned until you read through them all. You therefore have two options really:

1) Open the results with a reader, read through the results and keep a counter incrementing

2) Run another query with a count() around the query.

I would go with option 1 as you generally don't need to know how many records you have until you have processed all the data but let me know if this is a problem.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
alright, now I'm back to the validator question. I have the custom validator doing:

Code:
private void UnitVal_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
  try
   {
     string str = Convert.ToString(args.Value); 
     args.IsValid = (str != "") ? true : false; 
   }

  catch 
   { 
     args.IsValid = false; 
   }  
}

and it doesn't go to the function after I hit the add button. How do I force the function to happen before the add button function happens?
 
it actually only goes into the function if there is something in the text field...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top