public virtual void RemoveAttribute(string attributeName)
        {
            var attribute = _elementType.GetAttribute(attributeName);

            if (attribute != null)
            {
                object identifier = attribute.GetValue <object>(this);
                if (identifier != null)
                {
                    ((AttributeImpl)attribute).UnlinkReference(this, identifier);
                }
            }
            _domElement.RemoveAttribute(attributeName);
        }
Example #2
0
        private static void RestoreData(IDomElement e, CQ csQueryContext, HttpContext httpContext = null)
        {
            var    context = httpContext ?? HttpContext.Current;
            string value   = context.Request.Form[e["name"]];

            if (value != null)
            {
                switch (e.NodeName)
                {
                case "textarea":
                    e.InnerText = value;
                    break;

                case "input":
                    switch (e["type"])
                    {
                    case "checkbox":
                    case "radio":
                        if (value != null)
                        {
                            e.SetAttribute("checked");
                        }
                        else
                        {
                            e.RemoveAttribute("checked");
                        }
                        break;

                    case "hidden":
                    case "text":
                    case "password":
                    case "button":
                    case "submit":
                    case "image":
                        e.SetAttribute("value", value);
                        break;

                    case "file":
                        break;

                    default:
                        e.SetAttribute("value", value);
                        break;
                    }
                    break;

                case "select":
                    csQueryContext[e].Val(value);
                    break;

                default:
                    // just use value
                    csQueryContext[e].Val(value);
                    break;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Restore "value" to a single element.
        /// </summary>
        ///
        /// <exception cref="InvalidOperationException">
        /// Thrown when the requested operation is invalid.
        /// </exception>
        ///
        /// <param name="element">
        /// The element to restore a value to
        /// </param>
        /// <param name="csQueryContext">
        /// The context to which this element belongs
        /// </param>
        /// <param name="value">
        /// The value to restore
        /// </param>

        private static void RestoreData(IDomElement element, CQ csQueryContext, string value)
        {
            switch (element.NodeNameID)
            {
            case HtmlData.tagTEXTAREA:
                element.TextContent = value;
                break;

            case HtmlData.tagINPUT:
                switch (element["type"])
                {
                case "checkbox":
                case "radio":
                    if (value != null &&
                        ((element.Value ?? "on") == value))
                    {
                        element.SetAttribute("checked");
                    }
                    else
                    {
                        element.RemoveAttribute("checked");
                    }
                    break;

                case "hidden":
                case "text":
                case "password":
                case "button":
                case "submit":
                case "image":
                    element.SetAttribute("value", value);
                    break;

                case "file":
                    break;

                default:
                    element.SetAttribute("value", value);
                    break;
                }
                break;

            case HtmlData.tagSELECT:
            case HtmlData.tagBUTTON:
                csQueryContext[element].Val(value);
                break;

            default:
                throw new InvalidOperationException(String.Format("An unknown element type was found while restoring post data: '{0}'", element.NodeName));
            }
        }