Creating Validators in Custom ASP.NET Server Controls

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlndWVsIElzaWRvcm8=?=, Jul 27, 2006.

  1. 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
     
    =?Utf-8?B?TWlndWVsIElzaWRvcm8=?=, Jul 27, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?TWlndWVsIElzaWRvcm8=?=

    Teemu Keiski Guest

    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?


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    "Miguel Isidoro" <> wrote in message
    news:...
    > 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
     
    Teemu Keiski, Jul 27, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shamin
    Replies:
    1
    Views:
    3,551
    Martin Marinov
    Jul 20, 2004
  2. Ratman
    Replies:
    0
    Views:
    664
    Ratman
    Sep 14, 2004
  3. =?Utf-8?B?TFU=?=
    Replies:
    3
    Views:
    598
    Lucas Tam
    Mar 30, 2005
  4. rodchar
    Replies:
    0
    Views:
    396
    rodchar
    Nov 26, 2007
  5. Using validators on custom controls

    , Jun 24, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    135
Loading...

Share This Page