public bool CanHaveStatefulFields(Control control) {
			if (control is LiteralControl) //quickly removed the LiteralControls
				return false;
			if (control is UserControl || control is Page)
			{
                if (control is IStatefulFieldsControl)
                    if( ((IStatefulFieldsControl) control).IgnoreStatefulFields) 
                        return false;
			    return Attribute.GetCustomAttribute(control.GetType(), typeof (IgnoreStatefulFields)) == null;
			}
			Type t = control.GetType();
			LogFactory.Log.Debug("inspecting " + t +  control.ID + "(" + control.UniqueID + ")");
			if (AllowedTypes.Contains(t))
				return true;
			if (FilteredTypes.Contains(t))
				return false;
			foreach (Type ft in FilteredBaseTypes)
				if (t.IsSubclassOf(ft)) {
					FilteredTypes.Add(t);
					return false;
				}
			//this line took too much resources:
			//return Attribute.GetCustomAttribute(control.GetType(), typeof (HasStatefulField)) != null;
			return true;
		}
        private static void ClearControls(Control control)
        {
            for (int index = control.Controls.Count - 1; index >= 0; index--)
            {
                ClearControls(control.Controls[index]);
            }

            if (!(control is TableCell))
            {
                if (control.GetType().GetProperty("SelectedItem") != null)
                {
                    LiteralControl m_Literal = new LiteralControl();
                    control.Parent.Controls.Add(m_Literal);

                    m_Literal.Text = (string)control.GetType().GetProperty("SelectedItem").GetValue(control, null);
                    control.Parent.Controls.Remove(control);
                }
                else
                {
                    if (control.GetType().GetProperty("Text") != null)
                    {
                        LiteralControl m_Literal = new LiteralControl();
                        control.Parent.Controls.Add(m_Literal);
                        m_Literal.Text = (string)control.GetType().GetProperty("Text").GetValue(control, null);
                        control.Parent.Controls.Remove(control);
                    }
                }
            }
        }
Example #3
0
        public static void ClearForm(Control container, FormClearOptions option, bool check_nc)
        {
            try
            {
                switch (option)
                {
                    case FormClearOptions.ClearAll:

                        if (check_nc)
                        {
                            if (container.ID != null)
                                if (container.ID.EndsWith("_nc"))
                                    break;
                        }

                        if (container.GetType().Equals(typeof(TextBox)))
                        {
                            TextBox txtBox = ((TextBox)container);
                            txtBox.Text = string.Empty;
                        }
                        else if (container.GetType().Equals(typeof(DropDownList)))
                        {
                            DropDownList ddl = ((DropDownList)container);
                            ddl.SelectedValue = string.Empty;
                        }
                        else if (container.GetType().Equals(typeof(CheckBox)))
                        {
                            CheckBox chk = ((CheckBox)container);
                            chk.Checked = false;
                        }
                        else if (container.GetType().Equals(typeof(RadioButtonList)))
                        {
                            RadioButtonList rbl = ((RadioButtonList)container);
                            rbl.SelectedIndex = -1;
                        }
                        else if (container.GetType().Equals(typeof(RadioButton)))
                        {
                            RadioButton rb = ((RadioButton)container);
                            rb.Checked = false;
                        }
                        else if (container.HasControls())
                        {
                            foreach (Control ctrl in container.Controls)
                                ClearForm(ctrl, option, check_nc);
                        }
                        break;

                    default:
                        break;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// Iterates through all the controls of the first control and 
 /// recursiv calling this funktion again until the control has no more sub Controls.
 /// If one control is a Button or a LinkButton, the eventscript will be added to the event
 /// </summary>
 /// <param name="ctrl">The Control to iterate through</param>
 /// <param name="eventString">the name of the event to assign</param>
 /// <param name="eventScript">The script to assign to the event</param>
 public static void AddEventToAllSubmitItems(Control ctrl, string eventString, string eventScript)
 {
     foreach (Control control in ctrl.Controls)
     {
         if (control != null)
         {
             AddEventToAllSubmitItems(control, eventString, eventScript);
         }
     }
     if (ctrl.GetType() == typeof(Button) || ctrl.GetType() == typeof(LinkButton) || ctrl.GetType() == typeof(ImageButton))
     {
         SetWebControlEvent((WebControl)ctrl, eventString, eventScript);
     }
 }
Example #5
0
        public static void RegisterScriptInclude(Control control, string script) {
#if V2
#if DEBUG
            if (!control.Page.ClientScript.IsStartupScriptRegistered(script))
                control.Page.ClientScript.RegisterStartupScript(control.GetType(), control.GetType().FullName, GetAssemblyResource(script), true);
#else
            if (!control.Page.ClientScript.IsClientScriptIncludeRegistered(script))
                control.Page.ClientScript.RegisterClientScriptResource(control.GetType(), script);
#endif
#else
            if (!control.Page.IsStartupScriptRegistered(script))
                control.Page.RegisterClientScriptBlock(control.GetType().FullName, "<script language=\"javascript\" type=\"text/javascript\">\n" + GetAssemblyResource(script) + "\n</script>\n");
#endif
        }
Example #6
0
        /// <summary>
        /// Adds the CSS class.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="classNameToAdd">The class name to add.</param>
        public static void AddCssClass(Control control, string classNameToAdd)
        {
            string cssClasses;
            if (control is HtmlControl)
            {
                cssClasses = ((HtmlControl)control).Attributes[Constants.HtmlAttributes.Class];
            }
            else if (control is WebControl)
            {
                cssClasses = ((WebControl)control).CssClass;
            }
            else
            {
                throw new NotSupportedException("Type '" + control.GetType() + "' is not supported!");
            }

            if (String.IsNullOrEmpty(cssClasses))
            {
                cssClasses = String.Empty;
            }

            cssClasses += " " + classNameToAdd;
            if (control is HtmlControl)
            {
                ((HtmlControl)control).Attributes[Constants.HtmlAttributes.Class] = cssClasses;
            }
            else if (control is WebControl)
            {
                ((WebControl)control).CssClass = cssClasses;
            }
        }
        public static void ShowMessageBox(Control p, string Message, string BoxTitle, MessageBoxType type)
        {
            Message = Message.Replace("\r\n", "");
            Message = Message.Replace("<BR>", "{BR}");
            Message = Message.Replace("<", "{START}");
            Message = Message.Replace(">", "{END}");
            Message = Message.Replace("\"", "{Q}");


            string ImagePath = string.Format(p.ResolveUrl("~/App_Themes/MessageBox/{0}.png"), type.GetEnumName());

            string script = string.Format(@"<script type=""text/javascript"">
                                 ShowJQMessageBox(' <fieldset style=""direction:rtl;width:400px;max-width:600px;min-width: 300px;"" align=""center""><legend><img  align=""middle"" src=""{0}"" Width=""32"" />{1} </legend>  <span style=""direction:rtl;text-align:right"">{2}</span></fieldset>');
                               </script>", ImagePath, BoxTitle, HttpContext.Current.Server.HtmlEncode(Message));



            script = script.Replace("{BR}", "<BR>");
            script = script.Replace("{START}", "<");
            script = script.Replace("{END}", ">");
            script = script.Replace("{Q}", "\"");

            ScriptManager.RegisterClientScriptBlock(p, p.GetType(), "message", script, false);

        }
Example #8
0
 /// <summary>
 /// 为不同的控件赋值
 /// </summary>
 /// <param name="ctl">控件</param>
 /// <param name="oValue">值</param>
 public void aInitSetValue(Control ctl, object oValue)
 {
     string thisValue = string.Empty;
     if (oValue != null)
     {
         thisValue = oValue.ToString();
     }
     else
     {
         thisValue = "null";
     }
     switch (ctl.GetType().ToString())
     {
         case "System.Web.UI.WebControls.Literal":
             Literal lit = (Literal)ctl;
             lit.Text = thisValue;
             break;
         case "System.Web.UI.WebControls.TextBox":
             TextBox txt = (TextBox)ctl;
             txt.Text = thisValue;
             break;
         case "System.Web.UI.WebControls.RadioButtonList":
             RadioButtonList rbl = (RadioButtonList)ctl;
             rbl.SelectedValue = thisValue;
             break;
         case "System.Web.UI.WebControls.DropDownList":
             break;
     }
 }
Example #9
0
        public void InjectInto(Control control)
        {
            if (_cfg.TypeResolver == null)
            {
                throw new InvalidOperationException("Please configure your container bindings.");
            }

            var injectTheseProperties = _injectionMap.Lookup(control.GetType());
            foreach (var property in injectTheseProperties)
            {
                var instance = _cfg.TypeResolver.Resolve(property.Type);

                if (instance == null)
                {
                    System.Diagnostics.Debug.WriteLine("Attempt to inject value into member " + property.UnderlyingValue.Name + " resulted in a NULL.");
                }

                property.SetValue(control, instance);
            }

            foreach (var child in GetControlTree(control))
            {
                InjectInto(child);
            }
        }
Example #10
0
        public static void ExcedJS(Control c, string msg)
        {
            ValidPage(c);

            c.Page.ClientScript.RegisterStartupScript(c.GetType(), "__Exced",
                WrapJs(msg));
        }
Example #11
0
        /// <summary>
        /// ����
        /// </summary>
        /// <param name="c"></param>
        public static void Back(Control c)
        {
            ValidPage(c);

            c.Page.ClientScript.RegisterStartupScript(c.GetType(), "__Back",
                WrapJs("history.back();"));
        }
Example #12
0
        /// <summary>
        /// �رմ���
        /// </summary>
        /// <param name="p"></param>
        /// <param name="msg"></param>
        public static void Close(Control c)
        {
            ValidPage(c);

            c.Page.ClientScript.RegisterStartupScript( c.GetType(), "__Close",
                WrapJs( "window.close();" ));
        }
 public override void DataBindControl(IDesignerHost designerHost, Control control)
 {
     DataBinding runtimeDataBinding = ((IDataBindingsAccessor) control).DataBindings["Text"];
     if (runtimeDataBinding != null)
     {
         PropertyInfo property = control.GetType().GetProperty("Text");
         if ((property != null) && (property.PropertyType == typeof(string)))
         {
             DesignTimeDataBinding binding2 = new DesignTimeDataBinding(runtimeDataBinding);
             string str = string.Empty;
             if (!binding2.IsCustom)
             {
                 try
                 {
                     str = DataBinder.Eval(((IDataItemContainer) control.NamingContainer).DataItem, binding2.Field, binding2.Format);
                 }
                 catch
                 {
                 }
             }
             if ((str == null) || (str.Length == 0))
             {
                 str = System.Design.SR.GetString("Sample_Databound_Text");
             }
             property.SetValue(control, str, null);
         }
     }
 }
Example #14
0
        /// <summary>
        /// �ڿͻ�����ʾһ����Ϣ
        /// </summary>
        /// <param name="c"></param>
        /// <param name="msg"></param>
        public static void Alert( Control c , string msg )
        {
            ValidPage(c);

            c.Page.ClientScript.RegisterStartupScript( c.GetType(), "__Alert",
                WrapJs( string.Format( "alert(\"{0}\");" , JsEncoder.Encode( msg ) ) ) ) ;
        }
        private static void InvokeConstructor(IServiceProvider container, Control instance) {
            var type = instance.GetType();

            var constructor = GetConstructor(type);
            while (constructor == null && type != typeof (Page) && type != typeof (MasterPage) &&
                   type != typeof (UserControl) && type != null) {
                type = type.BaseType;
                constructor = GetConstructor(type);
            }

            if (constructor == null) {
                // only Default constructor
                return;
            }

            try {
                var args =
                    constructor.GetParameters().Select(x => container.GetRequiredService(x.ParameterType)).ToArray();
                constructor.Invoke(instance, args);
            }
            catch (Exception ex) {
                var message = Resources.Error_PageInitializationFail_Message(type.FullName, ex.Message);
                throw new InvalidOperationException(message, ex);
            }
        }
 public EzJavaScriptManager(Control control)
 {
     _page = control.Page;
     _control = control;
     _type = control.GetType();
     _isInUpdatePanel = _control.IsInUpdatePanel();
 }
Example #17
0
        /// <summary>
        /// ǰ��
        /// </summary>
        /// <param name="c"></param>
        public static void Forward(Control c)
        {
            ValidPage(c);

            c.Page.ClientScript.RegisterStartupScript(c.GetType(), "__Forward",
                WrapJs("history.go(1);"));
        }
        public void RegisterClientScript(Control control, string functionName, string param)
        {
            // initialize the function call as a string script
            string script = string.Format("{0}('{1}')", functionName, param);

            // register the startup script event to call the function
            ScriptManager.RegisterStartupScript(control, control.GetType(), Guid.NewGuid().ToString(), script, true);
        }
 private static void RegisterEmbeddedResource(Type type, Control control, string projectQualifiedResourceName, string scriptFormat)
 {
     if (control.Page.ClientScript.IsClientScriptIncludeRegistered(projectQualifiedResourceName))
         return;
     var resourceUrl = control.Page.ClientScript.GetWebResourceUrl(type, projectQualifiedResourceName);
     var includeTag = string.Format(scriptFormat, resourceUrl);
     control.Page.ClientScript.RegisterClientScriptBlock(control.GetType(), projectQualifiedResourceName, includeTag, false);
 }
 public static void ShowPopup(string id, Control control, bool addScript = false)
 {
     var sb = new System.Text.StringBuilder();
     sb.Append(@"<script type='text/javascript'>");
     sb.Append("$('"+id+"').modal('show');");
     sb.Append(@"</script>");
     ScriptManager.RegisterClientScriptBlock(control, control.GetType(), "ModalScript", sb.ToString(), addScript);
 }
Example #21
0
		/// <summary>
		/// Verifica se um controle está vazio.
		/// </summary>
		/// <param name="ctl">O controle</param>
		/// <returns>Verdadeiro se o controle está vazio, falso caso contrário</returns>
		/// <remarks>
		/// Um controle pode estar vazio pelos motivos abaixo:
		/// <list type="bullet">
		///		<item>Seu valor em <see cref="String"/> é igual a nulo ou a <see cref="String.Empty"/></item>
		///		<item>É um <see cref="ListControl"/> e não tem nenhum item selecionado</item>
		/// </list>
		/// </remarks>
		public static bool IsEmpty(Control ctl)
		{
			object val = GetValue(ctl);
			if (val == null) return true;
			if (val is Array) return ((Array) val).Length == 0;
			if (val is string) return ((string) val).Length == 0;

			throw new Exception("Control Type not supported: " + ctl.GetType().FullName);
		}
Example #22
0
			public override void AddAt(int index, Control child)
			{
				if (!(child is TableRow))
					throw new ArgumentException (HttpRuntime.FormatResourceString (
									"Cannot_Have_Children_Of_Type",
									"Table",
									child.GetType ().Name.ToString ()));
				base.AddAt (index, child);
			}
Example #23
0
 public void Execute(Page page, Control source, object argument)
 {
     var target = source.NamingContainer.FindControl((string)argument) as Label;
     if (target == null)
     {
         return;
     }
     target.Text = "I was updated by the UpdateLabelCommand via a " + source.GetType().Name;
 }
        static bool IncludeControl(Control serverControl)
        {
            var returnedVal = false;
            var controlType = serverControl.GetType().ToString();
            if(controlType.IndexOf("Sys.Extended.UI.maskededitextender", StringComparison.OrdinalIgnoreCase) != -1)
                returnedVal = true;

            return returnedVal;
        }
        public ControlLocalizer (Control control)
        {
            // use control base type name, not .ascx one!
            LocalResourceFile = Localization.GetResourceFile (control, control.GetType ().BaseType.Name + ".ascx");

            // skinobjects must use resourses from skin directory
            if (control is SkinObjectBase)
                LocalResourceFile = LocalResourceFile.Replace ("/Controls", string.Empty);
        }
Example #26
0
        public static void Show(string message, Control owner)
        {
            Page page = (owner as Page) ?? owner.Page;
            if (page == null) return;

            page.ClientScript.RegisterStartupScript(owner.GetType(),
                "ShowMessage", string.Format("<script type='text/javascript'>alert('{0}')</script>",
                message));
        }
 private string[] GetPropertyNames(Control control)
 {
     ArrayList list = new ArrayList();
     foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(control.GetType()))
     {
         list.Add(descriptor.Name);
     }
     list.Sort(Comparer.Default);
     return (string[]) list.ToArray(typeof(string));
 }
Example #28
0
        /// <summary>
        /// Initializes the <see cref="T:System.Web.UI.WebControls.BoundField" /> object.
        /// </summary>
        /// <param name="enableSorting">true if sorting is supported; otherwise, false.</param>
        /// <param name="control">The data control that owns the <see cref="T:System.Web.UI.WebControls.BoundField" />.</param>
        /// <returns>
        /// false in all cases.
        /// </returns>
        public override bool Initialize( bool enableSorting, Control control )
        {
            string script = @"
            $('.grid-table tr td span.date-field').tooltip({html: true, container: 'body', delay: { show: 100, hide: 100 }});
            $('.grid-table tr td span.date-field').click( function(){ $(this).tooltip('hide'); });;
            ";
            ScriptManager.RegisterStartupScript( control, control.GetType(), "date-field-popover", script, true );

            return base.Initialize( enableSorting, control );
        }
 private static bool IncludeControl(Control serverControl)
 {
     bool ReturnedVal = false;
     string ControlType = serverControl.GetType().ToString();
     if (ControlType.IndexOf("Sys.Extended.UI.maskededitextender", StringComparison.OrdinalIgnoreCase) != -1)
     {
         ReturnedVal = true;
     }
     return ReturnedVal;
 }
Example #30
0
 private static bool ContainsRecursive(Type controlType, Control container)
 {
     if(container.GetType() == controlType)
         return true;
     foreach (Control c in container.Controls)
     {
         if (ContainsRecursive(controlType, c))
             return true;
     }
     return false;
 }