Exemplo n.º 1
0
        private void PlaceButtons()
        {
            // substitute our controls into the template. regex is fast.
            var matches = Regex.Matches(CanvasHtml, "<formbutton[^>]*>*</formbutton>");//("<[^>]*>", "g");

            foreach (var match in matches)
            {
                string formfield       = match.ToString();
                var    id              = Regex.Match(match.ToString(), @"(?<=\bid="")[^""]*");
                var    text            = Regex.Match(match.ToString(), @"(?<=\btext="")[^""]*");
                var    value           = Regex.Match(match.ToString(), @"(?<=\bvalue="")[^""]*");
                var    groupvalidation = Regex.Match(match.ToString(), @"(?<=\bGroupValidation="")[^""]*");
                var    onclick         = Regex.Match(match.ToString(), @"(?<=\bonclick="")[^""]*");

                if (value.ToString() == "Save")
                {
                    sbutton = new Button {
                        ID = id.ToString(), ValidationGroup = groupvalidation.ToString(), OnClientClick = onclick.ToString(), Text = text.ToString()
                    };
                    //Container.Controls.Add(sbutton);
                    CanvasHtml = CanvasHtml.Replace(match.ToString(), RenderControl(sbutton));
                    if (String.IsNullOrEmpty(groupvalidation.ToString()))
                    {
                        foreach (Control control in Controls)
                        {
                            Type type = control.GetType();
                            if (type.IsSubclassOf(typeof(BaseValidator)))
                            {
                                BaseValidator validator = control as BaseValidator;
                                validator.ValidationGroup = groupvalidation.ToString();
                            }
                        }
                    }
                }

                /*
                 * if (value.ToString() == "Cancel")
                 * {
                 *  cbutton = new Button { ID = id.ToString(), OnClientClick = onclick.ToString(), Text = text.ToString() };
                 *  //Container.Controls.Add(cbutton);
                 *  CanvasHtml = CanvasHtml.Replace(match.ToString(), RenderControl(cbutton));
                 * }
                 */
            }
        }
Exemplo n.º 2
0
        private void MoveFormElements()
        {
            // substitute our controls into the template. regex is fast.
            var matches = Regex.Matches(CanvasHtml, "<formfield[^>]*>*</formfield>");

            foreach (var match in matches)
            {
                string formfield    = match.ToString();
                var    name         = Regex.Match(match.ToString(), @"(?<=\bname="")[^""]*");
                var    internalname = Regex.Match(match.ToString(), @"(?<=\binternalname="")[^""]*");
                var    staticname   = Regex.Match(match.ToString(), @"(?<=\bstaticname="")[^""]*");

                var control = FindControl(this, name.ToString());
                if (control == null)
                {
                    control = FindControl(this, internalname.ToString());
                    if (control == null)
                    {
                        control = FindControl(this, staticname.ToString());
                    }
                }

                if (control != null)
                {
                    List <Control> validators = FindValidators(this, control);
                    if (validators.Count > 0)
                    {
                        CanvasHtml = CanvasHtml.Replace(match.ToString(), RenderControl(control, validators));
                    }
                    else
                    {
                        CanvasHtml = CanvasHtml.Replace(match.ToString(), RenderControl(control));
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (Replacements != null)
            {
                // make the additional replacements
                foreach (var replacement in Replacements)
                {
                    CanvasHtml = CanvasHtml.Replace(replacement.Key, replacement.Value);
                }
            }

            UpdatePanel         panel    = (UpdatePanel)Container.Parent;
            FormContentTemplate template = (FormContentTemplate)panel.ContentTemplate;

            CanvasHtml = template.innerHtml;

            if (!string.IsNullOrEmpty(CanvasHtml))
            {
                PlaceButtons();

                if (Changed)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "UpdateForm", "UpdateForm();", true);

                    var matches = Regex.Matches(CanvasHtml, "<div[^>]*>");
                    foreach (var match in matches)
                    {
                        var name = Regex.Match(match.ToString(), @"(?<=\bid="")[^""]*");

                        if ((name.ToString().ToLower() == "successful") && Result)
                        {
                            var    style     = Regex.Match(match.ToString(), @"(?<=\bstyle="")[^""]*");
                            string proccesed = match.ToString().Replace(style.ToString(), "display:block;");
                            CanvasHtml = CanvasHtml.Replace(match.ToString(), proccesed);
                            continue;
                        }

                        if ((name.ToString().ToLower() == "unsuccessful") && !Result)
                        {
                            var    style     = Regex.Match(match.ToString(), @"(?<=\bstyle="")[^""]*");
                            string proccesed = match.ToString().Replace(style.ToString(), "display:block;");
                            CanvasHtml = CanvasHtml.Replace(match.ToString(), proccesed);
                            MoveFormElements();
                            continue;
                        }

                        if (Result)
                        {
                            var    style     = Regex.Match(match.ToString(), @"(?<=\bstyle="")[^""]*");
                            string proccesed = match.ToString().Replace(style.ToString(), "display:none;");
                            CanvasHtml = CanvasHtml.Replace(match.ToString(), proccesed);
                            continue;
                        }

                        /*
                         * else
                         * {
                         *  var style = Regex.Match(match.ToString(), @"(?<=\bstyle="")[^""]*");
                         *  string proccesed = match.ToString().Replace(style.ToString(), "display:block;");
                         *  CanvasHtml = CanvasHtml.Replace(match.ToString(), proccesed);
                         *  continue;
                         *
                         * }
                         */
                    }
                }
                else
                {
                    MoveFormElements();
                }
            }

            writer.Write(CanvasHtml);

            var postbackReference = Page.ClientScript.GetPostBackEventReference(this, "ProcessForm", true);
            var postbackScript    = String.Format("function ProcessForm() {{ {0}; }}", postbackReference);

            writer.WriteLine(@"<script type=""text/javascript"">");
            writer.WriteLine(postbackScript);
            writer.WriteLine("</script>");
            //base.Render(writer);
        }