protected void Page_PreRender(object sender, EventArgs e)
    {
        SetVisibility(BannerType);

        // Display appropriate controls and fill them with values.
        switch (BannerType)
        {
        case BannerTypeEnum.HTML:
        {
            if (!string.IsNullOrEmpty(providedValue))
            {
                htmlBanner.ResolvedValue = providedValue;
            }
        }
        break;

        case BannerTypeEnum.Plain:
        {
            if (!string.IsNullOrEmpty(providedValue))
            {
                macroEditorPlain.Text = providedValue;
            }
        }
        break;

        case BannerTypeEnum.Image:
        {
            if (!string.IsNullOrEmpty(providedValue))
            {
                BannerImageAttributes bannerImage = BannerManagementHelper.DeserializeBannerImageAttributes(providedValue);

                imsImage.Value   = bannerImage.Src;
                txtImgTitle.Text = bannerImage.Title;
                txtImgAlt.Text   = bannerImage.Alt;
                txtImgClass.Text = bannerImage.Class;
                txtImgStyle.Text = bannerImage.Style;
            }
        }
        break;
        }
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string bannerCategoryCodeName = ValidationHelper.GetString(GetValue("BannerCategoryCodeName"), "");

        BannerCategoryInfo bannerCategory = BannerCategoryInfoProvider.GetBannerCategoryInfoFromSiteOrGlobal(bannerCategoryCodeName, CMSContext.CurrentSiteID);

        if ((bannerCategory == null) || (bannerCategory.BannerCategoryEnabled == false))
        {
            Visible = !HideIfBannerNotFound;
            return;
        }

        if (URLHelper.IsPostback() && KeepPreviousBannerOnPostBack && BannerIDViewState.HasValue)
        {
            bannerReused = true;
            banner       = BannerInfoProvider.GetBannerInfo(BannerIDViewState.Value);
        }

        // If random banner should be picked or banner from viewstate was not found
        if (banner == null)
        {
            bannerReused = false;
            // Get random banner from selected category. Decrement hits left for this banner only if page is displayed on the live site.
            banner = BannerInfoProvider.GetRandomValidBanner(bannerCategory.BannerCategoryID, (currentViewMode == ViewModeEnum.LiveSite));
        }

        // Exits if no banner was found
        if (banner == null)
        {
            Visible = !HideIfBannerNotFound;
            return;
        }

        // Store banner id in the viewstate if the same banner should be used if request is postback
        if (KeepPreviousBannerOnPostBack)
        {
            BannerIDViewState = banner.BannerID;
        }

        string width       = ValidationHelper.GetString(GetValue("Width"), "");
        string height      = ValidationHelper.GetString(GetValue("Height"), "");
        string anchorClass = ValidationHelper.GetString(GetValue("AnchorClass"), "");
        bool   fakeLink    = ValidationHelper.GetBoolean(GetValue("FakeLink"), true);

        if (width != "")
        {
            lnkBanner.Style["width"] = width;
        }
        if (height != "")
        {
            lnkBanner.Style["height"] = height;
        }

        lnkBanner.CssClass = string.Format("CMSBanner {0}", anchorClass).Trim();

        lnkBanner.Visible = true;



        // Do not set link if we are not on the live site.
        if ((currentViewMode == ViewModeEnum.LiveSite) || (currentViewMode == ViewModeEnum.Preview))
        {
            // Link pointing to our custum handler which logs click and redirects
            string bannerRedirectURL =
                string.Format(
                    "{0}?bannerID={1}&redirectURL={2}",
                    URLHelper.ResolveUrl("~/CMSModules/BannerManagement/CMSPages/BannerRedirect.ashx"),
                    banner.BannerID,
                    HttpUtility.UrlEncode(URLHelper.ResolveUrl(banner.BannerURL))
                    );


            if (fakeLink)
            {
                // Defaultly href attribute will be set to 'nice' URL
                lnkBanner.Attributes.Add("href", URLHelper.ResolveUrl(banner.BannerURL));

                // After clicking href will be set to URL pointing to custom handler which counts clicks
                lnkBanner.Attributes.Add("onclick", string.Format("this.href='{0}';", bannerRedirectURL));

                // GECKO doesn't count middle mouse click as click, so onmouseup (or down) needs to be added
                lnkBanner.Attributes.Add("onmouseup", string.Format("this.href='{0}';", bannerRedirectURL));
            }
            else
            {
                // If faking links is disabled, set href to redirect url
                lnkBanner.Attributes.Add("href", bannerRedirectURL);
            }

            // Add target="_blank" attribute if link should be opened in new window
            if (banner.BannerBlank)
            {
                lnkBanner.Target = "_blank";
            }
        }

        if (banner.BannerType == BannerTypeEnum.Image)
        {
            BannerImageAttributes bannerImageAttributes = BannerManagementHelper.DeserializeBannerImageAttributes(banner.BannerContent);

            imgBanner.AlternateText = bannerImageAttributes.Alt;
            imgBanner.ToolTip       = bannerImageAttributes.Title;
            imgBanner.CssClass      = bannerImageAttributes.Class;
            imgBanner.Style.Value   = HTMLHelper.HTMLEncode(bannerImageAttributes.Style);

            imgBanner.ImageUrl = URLHelper.ResolveUrl(bannerImageAttributes.Src);

            imgBanner.Visible = true;
            ltrBanner.Visible = false;
        }
        else
        {
            string text = CMSContext.ResolveMacros(banner.BannerContent);

            ltrBanner.Text    = HTMLHelper.ResolveUrls(text, null, false);
            imgBanner.Visible = false;
            ltrBanner.Visible = true;

            if (banner.BannerType == BannerTypeEnum.HTML)
            {
                ControlsHelper.ResolveDynamicControls(this);
            }
        }
    }