Beispiel #1
0
 protected override void Render(HtmlTextWriter writer)
 {
     if (_usingSprites)
     {
         // Need to output the src element but without using the ImageUrl (ViewState)
         string imageUrl = ImageOptimizations.GetBlankImageSource(new HttpContextWrapper(Context).Request.Browser);
         ImageHtmlTextWriter imageHtmlTextWriter = new ImageHtmlTextWriter(writer, ResolveClientUrl(imageUrl));
         base.Render(imageHtmlTextWriter);
     }
     else
     {
         base.Render(writer);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Creates a reference to the sprite / inlined version of the desired image including special attributes.
        /// </summary>
        /// <param name="virtualPath">The relative path of the image to be displayed</param>
        /// <param name="htmlAttributes">Html Attributes of IDictionary form</param>
        /// <returns>Image tag.</returns>
        public static IHtmlString Image(string virtualPath, IDictionary <string, object> htmlAttributes)
        {
            ImageOptimizations.EnsureInitialized();

            TagBuilder htmlTag = new TagBuilder("img");

            htmlTag.MergeAttributes(htmlAttributes);

            HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);

            if (ImageOptimizations.LinkCompatibleCssFile(httpContext.Request.Browser) == null)
            {
                htmlTag.MergeAttribute("src", ResolveUrl(virtualPath));
                return(new HtmlString(htmlTag.ToString(TagRenderMode.SelfClosing)));
            }
            else
            {
                htmlTag.AddCssClass(ImageOptimizations.MakeCssClassName(virtualPath));
                htmlTag.MergeAttribute("src", ResolveUrl(ImageOptimizations.GetBlankImageSource(httpContext.Request.Browser)));
                return(new HtmlString(htmlTag.ToString(TagRenderMode.SelfClosing)));
            }
        }