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

Requiring a file be uploaded - set focus

1 Answer 115 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Thad
Top achievements
Rank 2
Thad asked on 04 May 2011, 09:09 PM
Version: 2010.2.929.40
VS 2010, C# 4.0

I'm adding a CustomValidator to a RadAsyncUpload control.  I found the post that states that the ControlToValidate must NOT be set to validate this type of control, so I am not setting it.

The validation works, and the error shows up, but Microsoft's built-in function ValidatorSetFocus(val, event) { is being overridden by the method in Telerik.Web.UI.Input.TextBox.RadInputScript.js, and that method is dependent upon the ControlToValidate and is throwing a JavaScript error when trying to set the style of the rad upload control.

This is what is being executed in lieu of Microsoft's code.  g is always null because d.controltovalidate is undefined so getting/setting g.style causes the "there is no 'style' property in 'null'" exception.

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;
}if((typeof(g)!="undefined")&&(g!=null)&&(g.tagName.toLowerCase()!="table"||(typeof(a)=="undefined")||(a==null))&&((g.tagName.toLowerCase()!="input")||(g.type.toLowerCase()!="hidden"))&&(typeof(g.disabled)=="undefined"||g.disabled==null||g.disabled==false)&&(typeof(g.visible)=="undefined"||g.visible==null||g.visible!=false)&&(IsInVisibleContainer(g)||c)){if(g.tagName.toLowerCase()=="table"&&(typeof(__nonMSDOMBrowser)=="undefined"||__nonMSDOMBrowser)){var e=g.getElementsByTagName("input");
var b=e[e.length-1];
if(b!=null){g=b;
}}if(typeof(g.focus)!="undefined"&&g.focus!=null){if(c&&document.getElementById(g.id+"_text")){document.getElementById(g.id+"_text").focus();
}else{if(c&&document.getElementById(g.id+"_dateInput_text")){document.getElementById(g.id+"_dateInput_text").focus();
}else{g.focus();
}}Page_InvalidControlToBeFocused=g;
}}};

Here is my client side validator for the RadAsyncUpload control.  Nothing different than what is in the forum posts except for that in my case rau does not have a GetUploadedFiles() method so I go directly to the internal property _uploadedFiles.  Not sure why that is the case.
function radAsyncUpload_OnClientValidate(source, arguments) {
    var rau = $find("<%= rauUpload.ClientID %>");
    arguments.IsValid = rau._uploadedFiles.length > 0;
}

Anyone have any thoughts??  I can't see why the RadInputControl.ValidatorSetFocus would be overriding the validation on an upload control...

Thanks!
Thad

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 11 May 2011, 10:06 AM
Hello Thad,

Indeed, RadInput seems to override ValidatorSetFocus, I am not sure of the exact reason because according to the product backlog it was a bug fix four years ago. Anyway, can you please paste you code  (including where you set style) so that we can reproduce the issue on our side and research it. And perhaps you can try setting ID to the ControlToValidate property and check how it is going on. As a workaround it is possible to save the default ValidatorSetFocus func and once RadInput override it, to override it once again. It is a bit of a hack, but I guess it will work.

Regards,
Genady Sergeev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
AsyncUpload
Asked by
Thad
Top achievements
Rank 2
Answers by
Genady Sergeev
Telerik team
Share this question
or