Bug with CustomValidator without ControlToValidate property

4 posts, 1 answers
  1. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 08 Nov 2010 Link to this post

    If you set a CustomValdiator on a Rad control (any one), but do NOT set a ControlToValidate property (this is perfectly legal per MS: http://msdn.microsoft.com/en-us/library/9eee01cx(VS.80).aspx) but you DO set SetFocus = "true," it will throw a Javascript error when executed because it is trying to resolve a reference to the ControlToValidate without first checking if the property was set.

    Here's a snippet of the file.  The error occurs on the last line where it attempts to get the style of object "g." 
    Telerik.Web.UI.RadInputControl.registerClass("Telerik.Web.UI.RadInputControl",Telerik.Web.UI.RadWebControl);
    if(typeof(ValidatorSetFocus)=="function"){ValidatorSetFocus=function(d,a){var g;
    if(typeof(d.controlhookup)=="string"){var f;
    if((typeof(a)!="undefined")&&(a!=null)){if((typeof(a.srcElement)!="undefined")&&(a.srcElement!=null)){f=a.srcElement;
    }else{f=a.target;
    }}if((typeof(f)!="undefined")&&(f!=null)&&(typeof(f.id)=="string")&&(f.id==d.controlhookup)){g=f;
    }}if((typeof(g)=="undefined")||(g==null)){g=document.getElementById(d.controltovalidate);
    }var c=false;
    if((g.style)&&(typeof(g.style.visibility)!="undefined")&&(g.style.visibility=="hidden")&&(typeof(g.style.width)!="undefined")&&(document.getElementById(g.id+"_text")||document.getElementById(g.id+"_dateInput_text"))&&(g.tagName.toLowerCase()=="input"||g.tagName.toLowerCase()=="textarea")){c=true;

    It should check if g == null before doing this.

    Steps to reproduce:
    1. Drag RadInput onto form
    2. Drag CustomValidator onto form
    3. Set OnServerVadliate to a proper function and add the function to the CodeBehind file
    4. Set SetFocus = "true"
    5. Run form
    6. Observe "Object expected" error

    Sample CustomValidator control:

    <asp:CustomValidator ID="CustomValidator1" runat="server" SetFocus="true" OnServerValidate="CheckSelectedClients" CssClass="validation-error" ErrorMessage="CustomValidator1"></asp:CustomValidator>

    Sample Server side validation function:
    protected void CheckSelectedClients(object source, ServerValidateEventArgs args)
    {
        try
        {
            if (selSelectedClientFamily.Items.Count > 0)
                args.IsValid = true;
            else
                args.IsValid = false;
        }
        catch (Exception)
        {
            args.IsValid = false;
        }
    }
  2. Answer
    Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 10 Nov 2010 Link to this post

    Hello Matthew,

    Thanks for the feedback. Surely, we can easily fix this, in fact we already have, however, I am curious in what scenario do you need both SetFocusOnError="true" with no ControlToValidate specified?

    Regards,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 10 Nov 2010 Link to this post

    Clearly, I don't actually need SetFocus="true", but I originally had a ControlToValidate but removed it for other reasons, which is when I found the bug.  I did spend a few hours tracking it down.  Aren't there some Telerik points for finding confirmed bugs?
  5. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 10 Nov 2010 Link to this post

    Hello Matthew,

    Your Telerik points have been updated.

    Greetings,
    Dimo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top