Creating my own Validation Control in ASP.NET 2.0

Discussion in 'ASP .Net Building Controls' started by philjohn@gmail.com, Mar 7, 2006.

  1. Guest

    Hi there,

    I'm attempting to create my own Validation Web Server controls to
    perform 2 different field checks:

    * Number of words
    * Number of letters

    I've followed most of the tutorials out there on the subject and keep
    running into a brick wall with ASP.NET 2.0 - the client side validation
    code isn't being run.

    The problem is, all of the tutorials out there have said to put the
    following in AddAttributesToRender

    writer.AddAttribute("evaluationfunction",
    "TextBoxLengthValidatorIsValid");
    writer.AddAttribute("maximumlength", this.MaximumLength.ToString());

    When I fire up the page in a browser, however, what this has done is
    add attributes to the span that serves as the validator text holder.

    All ASP.NET 2.0 validators output their attributes in a block of
    JavaScript that looks like this:

    var ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator =
    document.all ?
    document.all["ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator"]
    :
    document.getElementById("ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator");
    ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.controltovalidate
    = "ctl00_ContentMain_BrochureRepeater_ctl00_Title";
    ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.errormessage =
    "Title is a required field";
    ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.validationGroup
    = "BrochureGroup";
    ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.evaluationfunction
    = "RequiredFieldValidatorEvaluateIsValid";
    ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.initialvalue =
    "";

    I've searched high and low and can find no way of setting the
    "evaluationfunction" property that is output here, does anybody have
    any ideas, I could really use some about now!

    Thanks in advance for any help you ASP.NET gurus can give,

    Phil.
     
    , Mar 7, 2006
    #1
    1. Advertising

  2. Teemu Keiski Guest

    Hi,

    such script output of properties can be done with
    Page.ClientScript.RegisterExpandoAttribute
    http://msdn2.microsoft.com/en-us/li...ntscriptmanager.registerexpandoattribute.aspx

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

    <> wrote in message
    news:...
    > Hi there,
    >
    > I'm attempting to create my own Validation Web Server controls to
    > perform 2 different field checks:
    >
    > * Number of words
    > * Number of letters
    >
    > I've followed most of the tutorials out there on the subject and keep
    > running into a brick wall with ASP.NET 2.0 - the client side validation
    > code isn't being run.
    >
    > The problem is, all of the tutorials out there have said to put the
    > following in AddAttributesToRender
    >
    > writer.AddAttribute("evaluationfunction",
    > "TextBoxLengthValidatorIsValid");
    > writer.AddAttribute("maximumlength", this.MaximumLength.ToString());
    >
    > When I fire up the page in a browser, however, what this has done is
    > add attributes to the span that serves as the validator text holder.
    >
    > All ASP.NET 2.0 validators output their attributes in a block of
    > JavaScript that looks like this:
    >
    > var ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator =
    > document.all ?
    > document.all["ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator"]
    > :
    > document.getElementById("ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator");
    > ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.controltovalidate
    > = "ctl00_ContentMain_BrochureRepeater_ctl00_Title";
    > ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.errormessage =
    > "Title is a required field";
    > ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.validationGroup
    > = "BrochureGroup";
    > ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.evaluationfunction
    > = "RequiredFieldValidatorEvaluateIsValid";
    > ctl00_ContentMain_BrochureRepeater_ctl00_TitleValidator.initialvalue =
    > "";
    >
    > I've searched high and low and can find no way of setting the
    > "evaluationfunction" property that is output here, does anybody have
    > any ideas, I could really use some about now!
    >
    > Thanks in advance for any help you ASP.NET gurus can give,
    >
    > Phil.
    >
     
    Teemu Keiski, Mar 8, 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. Thom Anderson

    Creating my own label control

    Thom Anderson, Mar 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    385
    clintonG
    Mar 6, 2006
  2. Stefan Siegl
    Replies:
    1
    Views:
    807
  3. Saverio M.
    Replies:
    0
    Views:
    557
    Saverio M.
    Jul 3, 2006
  4. Thom Anderson

    Creating my own label control

    Thom Anderson, Mar 6, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    120
    clintonG
    Mar 6, 2006
  5. David Filmer
    Replies:
    17
    Views:
    304
    J. Romano
    Aug 18, 2004
Loading...

Share This Page