/// <include file='doc\AdRotator.uex' path='docs/doc[@for="AdRotator.Render"]/*' />
        /// <internalonly/>
        /// <devdoc>
        /// <para>Displays the <see cref='System.Web.UI.WebControls.AdRotator'/> on the client.</para>
        /// </devdoc>
        protected override void Render(HtmlTextWriter writer)
        {
            HyperLink bannerLink = new HyperLink();

            foreach (string key in Attributes.Keys)
            {
                bannerLink.Attributes[key] = Attributes[key];
            }

            if (this.ID != null && this.ID.Length > 0)
            {
                bannerLink.ID = this.ClientID;
            }
            if (this.navigateUrl != null && this.navigateUrl.Length > 0)
            {
                bannerLink.NavigateUrl = ResolveAdRotatorUrl(this.navigateUrl);
            }
            bannerLink.Target    = this.Target;
            bannerLink.AccessKey = this.AccessKey;
            bannerLink.Enabled   = this.Enabled;
            bannerLink.TabIndex  = this.TabIndex;
            bannerLink.RenderBeginTag(writer);

            // create inner Image
            Image bannerImage = new Image();

            // apply styles to image
            if (ControlStyleCreated)
            {
                bannerImage.ApplyStyle(this.ControlStyle);
            }
            bannerImage.AlternateText = this.alternateText;
            if (imageUrl != null && imageUrl.Length > 0)
            {
                bannerImage.ImageUrl = ResolveAdRotatorUrl(this.imageUrl);
            }
            bannerImage.ToolTip = this.ToolTip;
            bannerImage.RenderControl(writer);
            bannerLink.RenderEndTag(writer);;
        }
Exemple #2
0
        private void RenderLink(HtmlTextWriter writer, AdCreatedEventArgs adArgs)
        {
            HyperLink link = new HyperLink {
                NavigateUrl = adArgs.NavigateUrl,
                Target      = this.Target
            };

            if (base.HasAttributes)
            {
                foreach (string str in base.Attributes.Keys)
                {
                    link.Attributes[str] = base.Attributes[str];
                }
            }
            if (!string.IsNullOrEmpty(this.ID))
            {
                link.ID = this.ClientID;
            }
            if (!this.Enabled)
            {
                link.Enabled = false;
            }
            string str3 = (string)this.ViewState["AccessKey"];

            if (!string.IsNullOrEmpty(str3))
            {
                link.AccessKey = str3;
            }
            object obj2 = this.ViewState["TabIndex"];

            if (obj2 != null)
            {
                short num = (short)obj2;
                if (num != 0)
                {
                    link.TabIndex = num;
                }
            }
            link.RenderBeginTag(writer);
            Image image = new Image();

            if (base.ControlStyleCreated)
            {
                image.ApplyStyle(base.ControlStyle);
            }
            string alternateText = adArgs.AlternateText;

            if (!string.IsNullOrEmpty(alternateText))
            {
                image.AlternateText = alternateText;
            }
            else
            {
                IDictionary adProperties = adArgs.AdProperties;
                string      str5         = (this.AlternateTextField.Length != 0) ? this.AlternateTextField : "AlternateText";
                string      str6         = (adProperties == null) ? null : ((string)adProperties[str5]);
                if ((str6 != null) && (str6.Length == 0))
                {
                    image.GenerateEmptyAlternateText = true;
                }
            }
            image.UrlResolved = true;
            string imageUrl = adArgs.ImageUrl;

            if (!string.IsNullOrEmpty(imageUrl))
            {
                image.ImageUrl = imageUrl;
            }
            if (adArgs.HasWidth)
            {
                image.ControlStyle.Width = adArgs.Width;
            }
            if (adArgs.HasHeight)
            {
                image.ControlStyle.Height = adArgs.Height;
            }
            string str8 = (string)this.ViewState["ToolTip"];

            if (!string.IsNullOrEmpty(str8))
            {
                image.ToolTip = str8;
            }
            image.RenderControl(writer);
            link.RenderEndTag(writer);
        }
        private void RenderLink(HtmlTextWriter writer, AdCreatedEventArgs adArgs)
        {
            Debug.Assert(writer != null);
            Debug.Assert(adArgs != null);

            HyperLink bannerLink = new HyperLink();

            bannerLink.NavigateUrl = adArgs.NavigateUrl;
            bannerLink.Target      = Target;

            if (HasAttributes)
            {
                foreach (string key in Attributes.Keys)
                {
                    bannerLink.Attributes[key] = Attributes[key];
                }
            }

            string id = ID;

            if (!String.IsNullOrEmpty(id))
            {
                bannerLink.ID = ClientID;
            }

            if (!Enabled)
            {
                bannerLink.Enabled = false;
            }

            // WebControl's properties use a private flag to determine if a
            // property is set and does not return the value unless the flag is
            // marked.  So here we access those properites (inherited from WebControl)
            // directly from the ViewState bag because if ViewState bag reference
            // was copied to the helper class in the optimized case during the
            // Initialize() method, the flags of the properties wouldn't be set
            // in the helper class.
            string accessKey = (string)ViewState["AccessKey"];

            if (!String.IsNullOrEmpty(accessKey))
            {
                bannerLink.AccessKey = accessKey;
            }

            object o = ViewState["TabIndex"];

            if (o != null)
            {
                short tabIndex = (short)o;
                if (tabIndex != (short)0)
                {
                    bannerLink.TabIndex = tabIndex;
                }
            }

            bannerLink.RenderBeginTag(writer);

            // create inner Image
            Image bannerImage = new Image();

            // apply styles to image
            if (ControlStyleCreated)
            {
                bannerImage.ApplyStyle(ControlStyle);
            }

            string alternateText = adArgs.AlternateText;

            if (!String.IsNullOrEmpty(alternateText))
            {
                bannerImage.AlternateText = alternateText;
            }
            else
            {
                // 25914 Do not render empty 'alt' attribute if <AlternateText> tag is never specified
                IDictionary adProps    = adArgs.AdProperties;
                string      altTextKey = (AlternateTextField.Length != 0)
                                        ? AlternateTextField : AdCreatedEventArgs.AlternateTextElement;
                string altText = (adProps == null) ? null : (string)adProps[altTextKey];
                if (altText != null && altText.Length == 0)
                {
                    bannerImage.GenerateEmptyAlternateText = true;
                }
            }

            // Perf work: AdRotator should have resolved the NavigateUrl and
            // ImageUrl when assigning them and have UrlResolved set properly.
            bannerImage.UrlResolved = true;
            string imageUrl = adArgs.ImageUrl;

            if (!String.IsNullOrEmpty(imageUrl))
            {
                bannerImage.ImageUrl = imageUrl;
            }

            if (adArgs.HasWidth)
            {
                bannerImage.ControlStyle.Width = adArgs.Width;
            }

            if (adArgs.HasHeight)
            {
                bannerImage.ControlStyle.Height = adArgs.Height;
            }

            string toolTip = (string)ViewState["ToolTip"];

            if (!String.IsNullOrEmpty(toolTip))
            {
                bannerImage.ToolTip = toolTip;
            }

            bannerImage.RenderControl(writer);
            bannerLink.RenderEndTag(writer);
        }