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. Advertisements

  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. Advertisements

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. Matt
    Replies:
    14
    Views:
    4,546
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. Ravi Ambros Wallau
    Replies:
    0
    Views:
    4,266
    Ravi Ambros Wallau
    Jun 1, 2005
  3. Rob Nicholson
    Replies:
    6
    Views:
    1,041
    Rob Nicholson
    Jun 22, 2005
  4. Thom Anderson

    Creating my own label control

    Thom Anderson, Mar 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    442
    clintonG
    Mar 6, 2006
  5. Jens Jensen
    Replies:
    0
    Views:
    510
    Jens Jensen
    Jul 7, 2006
  6. Thom Anderson

    Creating my own label control

    Thom Anderson, Mar 6, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    187
    clintonG
    Mar 6, 2006
  7. Ravi Ambros Wallau
    Replies:
    0
    Views:
    482
    Ravi Ambros Wallau
    Jun 1, 2005
  8. David Thielen

    good sample of creating my own web control?

    David Thielen, Oct 18, 2006, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    247
    Walter Wang [MSFT]
    Oct 23, 2006
Loading...