can't get evaluationfunction attribute set correctly on CustomValidator

Discussion in 'ASP .Net Building Controls' started by TS, Aug 3, 2007.

  1. TS

    TS Guest

    i want to specify evalutionfunction for my custom validator control. i have
    tried many ways to get this to work, but in the end, the evaluationfunction
    attribute always gets rendered as the default
    "CustomValidatorEvaluateFunction":

    <span
    id="ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_cbC
    lientSigned" evaluationfunction="CustomValidatorEvaluateFunction"
    requiredfield="false" validatewhenempty="false" label="" validationGroup1
    mustBeChecked="true" style="color:Red;display:none;"></span>

    protected override void AddAttributesToRender(HtmlTextWriter writer){
    base.AddAttributesToRender(writer); string x;
    //this.ClientValidationFunction = "CheckBoxValidatorEvaluateIsValid";
    //writer.AddAttribute("evaluationfunction",
    "CheckBoxValidatorEvaluateIsValid", false);
    Attributes.Add("evaluationfunction", "CheckBoxValidatorEvaluateIsValid");
    writer.AddAttribute("mustBeChecked", MustBeChecked ? "true" : "false",
    false);
    }

    how do i do this correctly? I have tried to also not override
    AddAttributesToRender and instead in prerender just add these 2 attributes.
    No matter what i do, evaluationfunction gets overwritten somewhere

    what can i do?
     
    TS, Aug 3, 2007
    #1
    1. Advertising

  2. TS

    TS Guest

    i found out that this is in the base class to my class (which is inherited
    from customvalidator)
    protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter
    writer)

    {

    /// TODO: Get rid of the Custom EvaluationFunction

    Attributes.Remove("evaluationfunction");

    Attributes["evaluationfunction"] = "CustomValidatorEvaluateFunction";

    base.AddAttributesToRender(writer);

    writer.AddAttribute("requiredfield", RequiredField.ToString().ToLower());

    writer.AddAttribute("validatewhenempty",
    ValidateEmptyText.ToString().ToLower());

    writer.AddAttribute("label", Label);

    writer.AddAttribute("validationGroup1", ValidationGroup1);

    }

    i tried the same remove() function as above in my overriden method but no
    luck :(


    "TS" <> wrote in message
    news:...
    > i want to specify evalutionfunction for my custom validator control. i

    have
    > tried many ways to get this to work, but in the end, the

    evaluationfunction
    > attribute always gets rendered as the default
    > "CustomValidatorEvaluateFunction":
    >
    > <span
    >

    id="ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_cbC
    > lientSigned" evaluationfunction="CustomValidatorEvaluateFunction"
    > requiredfield="false" validatewhenempty="false" label="" validationGroup1
    > mustBeChecked="true" style="color:Red;display:none;"></span>
    >
    > protected override void AddAttributesToRender(HtmlTextWriter writer){
    > base.AddAttributesToRender(writer); string x;
    > //this.ClientValidationFunction = "CheckBoxValidatorEvaluateIsValid";
    > //writer.AddAttribute("evaluationfunction",
    > "CheckBoxValidatorEvaluateIsValid", false);
    > Attributes.Add("evaluationfunction", "CheckBoxValidatorEvaluateIsValid");
    > writer.AddAttribute("mustBeChecked", MustBeChecked ? "true" : "false",
    > false);
    > }
    >
    > how do i do this correctly? I have tried to also not override
    > AddAttributesToRender and instead in prerender just add these 2

    attributes.
    > No matter what i do, evaluationfunction gets overwritten somewhere
    >
    > what can i do?
    >
    >
     
    TS, Aug 3, 2007
    #2
    1. Advertising

  3. TS

    Teemu Keiski Guest

    They aren't written from Attributes collection but directly as expando
    attribute on the derived, concrete validator implementation

    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
    base.AddAttributesToRender(writer);
    if (base.RenderUplevel)
    {
    string controlId = this.ClientID;
    HtmlTextWriter writer2 = base.EnableLegacyRendering ? writer : null;
    base.AddExpandoAttribute(writer2, controlId, "evaluationfunction",
    "CustomValidatorEvaluateIsValid", false);
    if (this.ClientValidationFunction.Length > 0)
    {
    //client-side registration
    }
    }
    }

    AddExpandoAttribute is implemented as follows

    internal static void AddExpandoAttribute(Control control, HtmlTextWriter
    writer, string controlId, string attributeName, string attributeValue, bool
    encode)
    {
    if (writer != null)
    {
    writer.AddAttribute(attributeName, attributeValue, encode);
    }
    else
    {
    control.Page.ClientScript.RegisterExpandoAttribute(control,
    controlId, attributeName, attributeValue, encode);
    }
    }


    so basically you could try registering the attribute with
    control.Page.ClientScript.RegisterExpandoAttribute yourself.

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





    "TS" <> wrote in message
    news:...
    >i found out that this is in the base class to my class (which is inherited
    > from customvalidator)
    > protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter
    > writer)
    >
    > {
    >
    > /// TODO: Get rid of the Custom EvaluationFunction
    >
    > Attributes.Remove("evaluationfunction");
    >
    > Attributes["evaluationfunction"] = "CustomValidatorEvaluateFunction";
    >
    > base.AddAttributesToRender(writer);
    >
    > writer.AddAttribute("requiredfield", RequiredField.ToString().ToLower());
    >
    > writer.AddAttribute("validatewhenempty",
    > ValidateEmptyText.ToString().ToLower());
    >
    > writer.AddAttribute("label", Label);
    >
    > writer.AddAttribute("validationGroup1", ValidationGroup1);
    >
    > }
    >
    > i tried the same remove() function as above in my overriden method but no
    > luck :(
    >
    >
    > "TS" <> wrote in message
    > news:...
    >> i want to specify evalutionfunction for my custom validator control. i

    > have
    >> tried many ways to get this to work, but in the end, the

    > evaluationfunction
    >> attribute always gets rendered as the default
    >> "CustomValidatorEvaluateFunction":
    >>
    >> <span
    >>

    > id="ctl00_ctl00_ContentMainPlaceHolder_ApplicationContentMainPlaceHolder_cbC
    >> lientSigned" evaluationfunction="CustomValidatorEvaluateFunction"
    >> requiredfield="false" validatewhenempty="false" label="" validationGroup1
    >> mustBeChecked="true" style="color:Red;display:none;"></span>
    >>
    >> protected override void AddAttributesToRender(HtmlTextWriter writer){
    >> base.AddAttributesToRender(writer); string x;
    >> //this.ClientValidationFunction = "CheckBoxValidatorEvaluateIsValid";
    >> //writer.AddAttribute("evaluationfunction",
    >> "CheckBoxValidatorEvaluateIsValid", false);
    >> Attributes.Add("evaluationfunction", "CheckBoxValidatorEvaluateIsValid");
    >> writer.AddAttribute("mustBeChecked", MustBeChecked ? "true" : "false",
    >> false);
    >> }
    >>
    >> how do i do this correctly? I have tried to also not override
    >> AddAttributesToRender and instead in prerender just add these 2

    > attributes.
    >> No matter what i do, evaluationfunction gets overwritten somewhere
    >>
    >> what can i do?
    >>
    >>

    >
    >
     
    Teemu Keiski, Aug 5, 2007
    #3
  4. Thanks Teemu for your informative input.

    Hi TS,

    Please feel free to let us know if there's anything unclear. Thanks.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Aug 9, 2007
    #4
    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. Teep
    Replies:
    1
    Views:
    345
    Rick Spiewak
    Jun 27, 2004
  2. Sammy
    Replies:
    12
    Views:
    1,276
    Richard Tobin
    May 6, 2005
  3. Hamed
    Replies:
    3
    Views:
    702
    Eliyahu Goldin
    Jul 9, 2006
  4. Hamed

    How to generate readonly attribute correctly?

    Hamed, Jul 9, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    221
    Eliyahu Goldin
    Jul 9, 2006
  5. Replies:
    7
    Views:
    734
Loading...

Share This Page