Hi Matt,
I am a newbie and followed your c# code for a detailsview (for inserting) rather than a gridview object. Only slight difference is I need to to validate if the checkbox is selected and the textbox is empty.
I made the adjustment (think they are correct, please tell me if wrong) I have been debugging the code and it is working, (I.e the code identifies that the texbox is empty, marks the args.isvalid =false) but it does not stop the inserting of the record. It is really annoying me now. Do you have any suggestions, the setup has been configured the same as above (validate empty text = true) . I notice that in the other posts you mentioned "ClientValidationFunction", I just want it to fire "please enter number" the same way as the required field validator works (which requires no client side functions) , I suspect thats where I am getting lost maybe?. I would appreciate any insight you may have. Thanks in advance. Heres my code....
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator cv = (CustomValidator)source;
DetailsView myval = (DetailsView)cv.NamingContainer;
//GridViewRow row = (GridViewRow)cv.NamingContainer;
//assuming the id of the CheckBox control in the EditItemTemplate is "CheckBox1"
CheckBox chkBox = (CheckBox)myval.FindControl("cbLPGACertYN");
args.IsValid = true;
if (chkBox.Checked)
{
if (string.IsNullOrEmpty(args.Value))
args.IsValid = false;
}
}