Focus() public method

public Focus ( ) : void
return void
		/// <summary>Applies editor modifications after creating the control.</summary>
		/// <param name="editor">The editor to modify.</param>
		public virtual void Modify(Control editor)
		{
			if (this.DataBind)
				editor.DataBind();
			if (this.Focus)
				editor.Focus();
		}
Example #2
0
        /// <summary>
        /// 验证表单项
        /// </summary>
        /// <param name="field"></param>
        /// <param name="control"></param>
        /// <returns></returns>
        protected virtual Boolean ValidFormItem(FieldItem field, Control control)
        {
            // 必填项
            if (!field.IsNullable)
            {
                if (field.Type == typeof(String))
                {
                    if (String.IsNullOrEmpty((String)Entity[field.Name]))
                    {
                        WebHelper.Alert(String.Format("{0}不能为空!", field.DisplayName));
                        control.Focus();
                        return false;
                    }
                }
                else if (field.Type == typeof(DateTime))
                {
                    DateTime d = (DateTime)Entity[field.Name];
                    if (d == DateTime.MinValue || d == DateTime.MaxValue)
                    {
                        WebHelper.Alert(String.Format("{0}不能为空!", field.DisplayName));
                        control.Focus();
                        return false;
                    }
                }
            }

            return true;
        }
Example #3
0
        /// <summary>检查控件值是否为空,若为空,显示错误信息,并聚焦到控件上</summary>
        /// <param name="control">要检查的控件</param>
        /// <param name="errmsg">错误信息。若为空,将使用ToolTip</param>
        /// <returns></returns>
        public static Boolean CheckEmptyAndFocus(Control control, String errmsg)
        {
            if (control == null) throw new ArgumentNullException("control");

            if (control is WebControl && String.IsNullOrEmpty(errmsg)) errmsg = (control as WebControl).ToolTip;

            if (control is TextBox)
            {
                TextBox box = control as TextBox;
                if (!String.IsNullOrEmpty(box.Text)) return true;
            }
            else if (control is ListControl)
            {
                ListControl box = control as ListControl;
                if (!String.IsNullOrEmpty(box.Text)) return true;
            }
            else
                throw new XException("暂时不支持{0}控件!", control.GetType());

            control.Focus();
            if (!String.IsNullOrEmpty(errmsg)) Alert(errmsg);
            return false;
        }
Example #4
0
		public void Focus_Deny_Unrestricted ()
		{
			Control c = new Control ();
			page.Controls.Add (c);
			c.Focus ();
			// normal, no forms on page
		}