示例#1
0
        private void EvalKeepInSessionAttributeSet(TemplateControl instance, FieldInfo field)
        {
            var keepInSessionAttribute = GetAttributeFromField <KeepInSessionAttribute>(field);

            if (keepInSessionAttribute != null)
            {
                if (!KeepInSessionAttribute.TypeAllowed(field.FieldType))
                {
                    throw new InvalidTypeException("KeepInsession", field);
                }

                if (string.IsNullOrEmpty(keepInSessionAttribute.SessionKey))
                {
                    if (!(field.GetValue(instance) != null && Session[field.Name + "AutoSave"] == null))
                    {
                        field.SetValue(instance, Session[field.Name + "AutoSave"]);
                    }
                }
                else
                {
                    if (!(field.GetValue(instance) != null && Session[Request.QueryString[keepInSessionAttribute.SessionKey]] == null))
                    {
                        field.SetValue(instance, Session[Request.QueryString[keepInSessionAttribute.SessionKey]]);
                    }
                }
            }
        }
示例#2
0
        private void EvalKeepInViewStateAttributeSet(TemplateControl instance, FieldInfo field)
        {
            var keepInViewStateAttribute = GetAttributeFromField <KeepInViewStateAttribute>(field);

            if (keepInViewStateAttribute != null)
            {
                if (!KeepInSessionAttribute.TypeAllowed(field.FieldType))
                {
                    throw new InvalidTypeException("KeepInsession", field);
                }

                if (ViewState[field.Name + "AutoSave"] != null)
                {
                    field.SetValue(instance, Convert.ChangeType(ViewState[field.Name + "AutoSave"].ToString(), field.FieldType));
                }
                else
                {
                    field.SetValue(instance, keepInViewStateAttribute.DefaultValue);
                }
            }
        }