Ejemplo n.º 1
0
        /// <summary>
        /// Rendering of the wrapper and it's child controls
        /// </summary>
        protected override void CreateChildControls()
        {
            Controls.Clear();

            if (ContentTemplate != null)
            {
                componentHolder = new ComponentHolder(this);
                ContentTemplate.InstantiateIn(componentHolder);

                //field to validate
                Controls.Add(componentHolder);

                foreach (Control control in componentHolder.Controls)
                {
                    control.EnableViewState = true;
                }

                //triger image
                var    imageUrl         = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "InputValidationWrapper.Images." + (String.IsNullOrEmpty(this.MessageType) ? "error" : this.MessageType) + ".png");
                var    imageTextBg      = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "InputValidationWrapper.Images.bg.png");
                var    imageTextBgArrow = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "InputValidationWrapper.Images.bg-arrow.png");
                string style            = " style='background: url(" + imageUrl + ") no-repeat center center;'";
                string textBg           = " style='background: url(" + imageTextBg + ");'";
                string textBgArrow      = " style='background: url(" + imageTextBgArrow + ");'";

                Controls.Add(new LiteralControl("<i" + style + ">trigger</i>"));

                Controls.Add(new LiteralControl("<p" + textBg + "><label " + textBgArrow + " class='bottom_arrow'></label>" + this.Text + "</p>"));

                ClientScriptManager csm = Page.ClientScript;

                WebControl Child = ComponentHolder.FindControl(this.ControlToValidateID) as WebControl;


                if (!(Child is TextBox))
                {
                    throw new NotSupportedException("Wrapper can validate only TextBox currently.");
                }

                //!!!the validation invoker is there purely to bypass asp's problem with posting back on 'onblur' event when the control is inside of an update panel
                //Controls.Add(new LiteralControl("<a id=\"" + this.ClientID + "_Invoker\" href=\"javascript:" + @csm.GetPostBackEventReference(this, "RunValidation") + "\">Run</a>"));
            }
            else
            {
                Controls.Add(new LiteralControl(this.ID));
            }
        }
Ejemplo n.º 2
0
        //------------------------------ MISC METHODS --------------------------------------------

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public WebControl GetChildControl()
        {
            return(ComponentHolder.FindControl(this.ControlToValidateID) as WebControl);
        }