Beispiel #1
0
        public Dictionary <string, string> UpdateImage(int mediaId, string style, string linkTarget)
        {
            legacyAjaxCalls.Authorize();


            //load the control with the specified properties and render the output as a string and return it
            Page   page = new Page();
            string path = Umbraco.Core.IO.IOHelper.ResolveUrl(Umbraco.Core.IO.SystemDirectories.Umbraco) + "/controls/Images/ImageViewer.ascx";

            ImageViewer imageViewer = page.LoadControl(path) as ImageViewer;

            imageViewer.MediaId = mediaId;
            ImageViewer.Style _style = (ImageViewer.Style)Enum.Parse(typeof(ImageViewer.Style), style);
            imageViewer.ViewerStyle = _style;
            imageViewer.LinkTarget  = linkTarget;

            //this adds only the anchor with image to be rendered, not the whole control!
            page.Controls.Add(imageViewer);

            imageViewer.DataBind();

            StringWriter sw = new StringWriter();

            HttpContext.Current.Server.Execute(page, sw, false);

            Dictionary <string, string> rVal = new Dictionary <string, string>();

            rVal.Add("html", sw.ToString());
            rVal.Add("mediaId", imageViewer.MediaId.ToString());
            rVal.Add("width", imageViewer.FileWidth.ToString());
            rVal.Add("height", imageViewer.FileHeight.ToString());
            rVal.Add("url", imageViewer.MediaItemPath);
            rVal.Add("alt", imageViewer.AltText);

            return(rVal);
        }
		protected override void CreateChildControls()
		{
			base.CreateChildControls();

			//if preview is enabled, add it to the wrapper
			if (_showpreview)
			{
                //create the preview wrapper
                PreviewContainer = new HtmlGenericControl("div");
                PreviewContainer.ID = "preview";
                Controls.Add(PreviewContainer);

                ImgViewer = (ImageViewer)Page.LoadControl(IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/controls/Images/ImageViewer.ascx");
				ImgViewer.ID = "ImgViewer";
				ImgViewer.ViewerStyle = ImageViewer.Style.ImageLink;	
				
				PreviewContainer.Style.Add(HtmlTextWriterStyle.MarginTop, "5px");
				PreviewContainer.Controls.Add(ImgViewer);
			}			
		}