Beispiel #1
0
        public string GetScript(WebControl c, PropertyInfo property)
        {
            StringBuilder sb = new StringBuilder();

            if (!c.CallbackValues.ContainsKey(property.Name))
            {
                return(null);
            }

            object value = c.CallbackValues[property.Name];

            if (!string.IsNullOrEmpty(this.Script))
            {
                sb.AppendFormat(this.Script, c.ClientID, JSON.Serialize(value));
            }
            else if (!string.IsNullOrEmpty(this.MethodName))
            {
                MethodInfo method = c.GetType().GetMethod(this.MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { property.PropertyType }, null);
                if (method != null)
                {
                    method.Invoke(c, new object[] { value });
                }
            }
            else //simple script generating
            {
                switch (this.GenerateMode)
                {
                case AutoGeneratingScript.Simple:
                    sb.AppendFormat(AjaxEventUpdateAttribute.AutoGenerateFormat, c.ClientID, JSON.Serialize(value), StringUtils.ToLowerCamelCase(property.Name));
                    break;

                case AutoGeneratingScript.WithSet:
                    sb.AppendFormat("{0}.set{2}({1});", c.ClientID, JSON.Serialize(value), property.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public object this[string key]
        {
            get
            {
                return(this.ViewState[key]);
            }
            set
            {
                this.ViewState[key] = value;
                if (Ext.IsAjaxRequest && control.AllowCallbackScriptMonitoring)
                {
                    PropertyInfo pi = control.GetType().GetProperty(key);

                    if (pi == null)
                    {
                        return;
                    }

                    object[] attrs = pi.GetCustomAttributes(typeof(AjaxEventUpdateAttribute), true);

                    if (attrs.Length > 0)
                    {
                        this.control.CallbackValues[key] = value;
                        ((AjaxEventUpdateAttribute)attrs[0]).RegisterScript(this.control, pi);
                    }
                    else
                    {
                        ClientConfigAttribute attr = ClientConfig.GetClientConfigAttribute(pi);
                        if (attr != null)
                        {
                            this.control.CallbackValues[key] = value;
                            this.control.AddScript(string.Format(AjaxEventUpdateAttribute.AutoGenerateFormat, this.control.ClientID, JSON.Serialize(value), StringUtils.ToLowerCamelCase(pi.Name)));
                        }
                    }
                }
            }
        }