This is a migrated thread and some comments may be shown as answers.

Bug with CustomValidator without ControlToValidate property

3 Answers 174 Views
Input
This is a migrated thread and some comments may be shown as answers.
msigman
Top achievements
Rank 2
msigman asked on 08 Nov 2010, 06:50 PM
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;
    }
}

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 10 Nov 2010, 01:13 PM
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
0
msigman
Top achievements
Rank 2
answered on 10 Nov 2010, 03:32 PM
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?
0
Dimo
Telerik team
answered on 10 Nov 2010, 04:12 PM
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
Tags
Input
Asked by
msigman
Top achievements
Rank 2
Answers by
Dimo
Telerik team
msigman
Top achievements
Rank 2
Share this question
or