function WebForm_AutoFocus (id)
{
- var x = document.getElementById ? document.getElementById (id) :
- ((document.all) ? document.all [id] : null);
+ var x = WebForm_GetElementById (id);
- if (typeof (x) != 'undefined') {
- x.focus();
+ if (x && (!WebForm_CanFocus(x))) {
+ x = WebForm_FindFirstFocusableChild(x);
}
+ if (x) { x.focus(); }
+}
+
+function WebForm_CanFocus(element) {
+ if (!element || !(element.tagName) || element.disabled) {
+ return false;
+ }
+ if (element.type && element.type.toLowerCase() == "hidden") {
+ return false;
+ }
+ var tagName = element.tagName.toLowerCase();
+ return (tagName == "input" ||
+ tagName == "textarea" ||
+ tagName == "select" ||
+ tagName == "button" ||
+ tagName == "a");
+}
+
+function WebForm_FindFirstFocusableChild(element) {
+ if (!element || !(element.tagName)) {
+ return null;
+ }
+ var tagName = element.tagName.toLowerCase();
+ if (tagName == "undefined") {
+ return null;
+ }
+ var children = element.childNodes;
+ if (children) {
+ for (var i = 0; i < children.length; i++) {
+ try {
+ if (WebForm_CanFocus(children[i])) {
+ return children[i];
+ }
+ else {
+ var focused = WebForm_FindFirstFocusableChild(children[i]);
+ if (WebForm_CanFocus(focused)) {
+ return focused;
+ }
+ }
+ } catch (e) {
+ }
+ }
+ }
+ return null;
}
function wasControlEnabled (id)
return false;
}
-function WebForm_ReEnableControls()
+function WebForm_ReEnableControls (currForm)
{
- if (typeof (theForm) == 'undefined')
+ currForm = currForm || theForm;
+ if (typeof (currForm) == 'undefined')
return;
- for (var i = 0; i < theForm.childNodes.length; i ++) {
- var node = theForm.childNodes[i];
+ for (var i = 0; i < currForm.childNodes.length; i ++) {
+ var node = currForm.childNodes[i];
if (node.disabled && wasControlEnabled (node.id))
node.disabled = false;
}
if (pval && typeof(Page_ClientValidate) == "function" && !Page_ClientValidate(vg))
return;
+ var form = WebForm_GetFormFromCtrl (ctrl);
if (url != null)
- theForm.action = url;
+ form.action = url;
if (csubm)
__doPostBack (ctrl, par);
}
+function WebForm_GetFormFromCtrl (id)
+{
+ // We need to translate the id from ASPX UniqueID to its ClientID.
+ var ctrl = WebForm_GetElementById (id.replace(/:/g, "_"));
+ while (ctrl != null) {
+ if (ctrl.isAspForm)
+ return ctrl;
+ ctrl = ctrl.parentNode;
+ }
+ return theForm;
+}
+
+function WebForm_GetElementById (id)
+{
+ return document.getElementById ? document.getElementById (id) :
+ document.all ? document.all [id] :
+ document [id];
+}
+
+function WebForm_FireDefaultButton(event, target)
+{
+ if (event.keyCode != 13) {
+ return true;
+ }
+ if(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea")) {
+ return true;
+ }
+ var defaultButton = WebForm_GetElementById(target);
+ if (defaultButton && typeof(defaultButton.click) != "undefined") {
+ defaultButton.click();
+ event.cancelBubble = true;
+ return false;
+ }
+ return true;
+}
+
+