Creating Validators in Custom ASP.NET Server Controls

G

Guest

Hi all,

I am developing a Custom ASP.NET Server Controls that generates a form based
on a xml file and want to include RequiredFieldValidator for mandatory
questions. I am using the following function:

private RequiredFieldValidator CreateRequiredFieldValidator(string
controlToValidateID, string errorMessage)
{
RequiredFieldValidator requiredFieldValidator = new
RequiredFieldValidator();
requiredFieldValidator.ControlToValidate = controlToValidateID;
requiredFieldValidator.Display = ValidatorDisplay.Dynamic;
requiredFieldValidator.ErrorMessage = errorMessage;

return requiredFieldValidator;
}

Everytime I want to include a requiredfieldvalidator i call this function as
follows:

RequiredFieldValidator requiredFieldValidator =
CreateRequiredFieldValidator(controlID, "Required field");
responsePanel.Controls.Add(requiredFieldValidator);

The responsePanel is a Panel control that maps to a html <div> element. I
leave the EnableClientScript enabled so that I can see the javascript code
that is generated. I saw the html source that is generated and it seems ok
and the ControlToValidate property is properly set with the right ids. All
the javascript functions are there or are in the included WebResource.axd
http handler. I even tried to set the EnableClientScript property to false
and it doesn't work also.

Any sugestions?

Thanks
Miguel
 
T

Teemu Keiski

Hi,

can you clarify a bit how it doesn't work? Can you also show a bit more code
how you are using it in scenario where it fails?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top