コード例 #1
0
        public string GetValue(Control ctrl1, XmlNode renderingDocument)
        {
            FiscalCodeControl ctrl      = (FiscalCodeControl)ctrl1.Controls[1];
            XmlDocument       doc       = new XmlDocument();
            string            root      = String.IsNullOrEmpty(this.Name) ? "null" : this.Name;
            XmlNode           nodeValue = doc.CreateElement(root);
            XmlElement        elem      = doc.CreateElement("Value");

            doc.AppendChild(nodeValue);
            nodeValue.AppendChild(elem);
            nodeValue.FirstChild.InnerText = ctrl.Text.FromNotEncodedRender2XmlValue();
            if (nodeValue.FirstChild.InnerText == "" && Common.getElementFromSchema(baseSchema).IsNillable)
            {
                elem.SetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
            }
            return(doc.OuterXml);
        }
コード例 #2
0
        public Control GetWebControl(System.Web.HttpServerUtility server, XmlNode renderingDocument)
        {
            PlaceHolder ph = new PlaceHolder();

            Label lbl = new Label();

            if (renderingDocument.Attributes["renderedLabel"] != null)
            {
                lbl.Text = renderingDocument.Attributes["renderedLabel"].Value.FromXmlValue2Render(server);
            }
            else
            {
                lbl.Text = this.Name.FromXmlName2Render(server);
            }
            lbl.CssClass = "label";
            ph.Controls.Add(lbl);

            FiscalCodeControl sbox = new FiscalCodeControl(this);

            //sbox.CausesValidation = false;

            if (renderingDocument.Attributes["class"] != null)
            {
                sbox.CssClass = renderingDocument.Attributes["class"].Value.FromXmlValue2Render(server);
            }
            if (renderingDocument.Attributes["rel"] != null)
            {
                sbox.Attributes.Add("rel", renderingDocument.Attributes["rel"].Value.FromXmlValue2Render(server));
            }
            if (renderingDocument.Attributes["description"] != null)
            {
                sbox.ToolTip = renderingDocument.Attributes["description"].Value.FromXmlValue2Render(server);
            }

            // Setting properties
            sbox.TextMode = TextBoxMode.SingleLine;
            if (renderingDocument.Attributes["rows"] != null)
            {
                string ns = renderingDocument.Attributes["rows"].Value.FromXmlValue2Render(server);
                int    n;
                if (int.TryParse(ns, out n) && n > 1)
                {
                    sbox.TextMode = TextBoxMode.MultiLine;
                    sbox.Rows     = n;
                }
            }
            if (renderingDocument.Attributes["hiddentext"] != null)
            {
                if (renderingDocument.Attributes["hiddentext"].Value.FromXmlValue2Render(server).ToLower().Equals("true"))
                {
                    sbox.TextMode = TextBoxMode.Password;
                }
            }

            ph.Controls.Add(sbox);

            //--- ADD validators ---

            if (!Common.getElementFromSchema(baseSchema).IsNillable)
            {
                RequiredFieldValidator rqfv = new RequiredFieldValidator();
                rqfv.ErrorMessage      = "Required fields shouldn't be empty";
                rqfv.ControlToValidate = sbox.ID;
                rqfv.ValidationGroup   = "1";
                rqfv.Display           = ValidatorDisplay.Dynamic;
                ph.Controls.Add(rqfv);
            }

            if (((XmlSchemaSimpleType)Common.getElementFromSchema(baseSchema).SchemaType) == null)
            {
                return(ph);
            }

            XmlSchemaObjectCollection constrColl =
                ((XmlSchemaSimpleTypeRestriction)((XmlSchemaSimpleType)Common.getElementFromSchema(baseSchema).SchemaType).Content).Facets;

            // Set validators from XSD
            foreach (XmlSchemaFacet facet in constrColl)
            {
                if (facet is XmlSchemaPatternFacet)
                {
                    ph.Controls.Add(getPatternValidator(facet.Value, sbox.ID));
                }
            }

            //---

            return(ph);
        }