English 中文(简体)
视力演播室2008/2010年设计师无法再配上与设计师的校对校对
原标题:WebControl decorated with Designer attribute cannot be resized in Visual Studio 2008/2010 designer

We have a subclassed WebControl which is decorated with the Designer attribute and displays an image in GetDesignTimeHtml. It is built using VS 2008 Sp1. Under VS 2005, when placed in the toolbox, and dragged into an aspx page in design mode, it behaves just fine. However, in both VS 2008 Sp1 and VS 2010 Sp1, the image cannot be resized in design mode. I have recreated the problem using the following code:

using System;    
using System.ComponentModel;    
using System.Security.Permissions;    
using System.Web;    
using System.Web.UI;    
using System.Web.UI.WebControls;    
using System.Web.UI.Design.WebControls;    
using System.ComponentModel.Design;    

using System.Collections;    
using System.Configuration;    
using System.Web.Configuration;    
using System.Web.UI.Design;    
using System.Text;    
using System.Reflection;    
using System.Windows.Forms;    
using System.Drawing;    

namespace Samples.AspNet.CS.Controls    
{    
    [    
    Designer(typeof(WelcomeLabelDesigner)),    
    DefaultPropertyAttribute("ID"),    
    ToolboxBitmap(typeof(WelcomeLabel), "Samples.AspNet.CS.Controls.WecomeLabel"),    
    ToolboxData("<{0}:WelcomeLabel runat="server" Height= 256px  Width= 256px  > </{0}:WelcomeLabel>")    
    ]    
    public class WelcomeLabel : WebControl    
    {    
        [    
        Bindable(true),    
        Category("Appearance"),    
        DefaultValue(""),    
        Description("The welcome message text."),    
        Localizable(true)    
        ]    

        public virtual string Text    
        {    
            get    
            {    
                string s = (string)ViewState["Text"];    
                return (s == null) ? String.Empty : s;    
            }    
            set    
            {    
                ViewState["Text"] = value;    
            }    
        }    

        protected override void RenderContents(HtmlTextWriter writer)    
        {    
            writer.Write("Testing how the App_Code directory works.<br>");     
            writer.WriteEncodedText(Text);    
            if (Context != null)    
            {    
                string s = Context.User.Identity.Name;    
                if (s != null && s != String.Empty)    
                {    
                    string[] split = s.Split( \ );    
                    int n = split.Length - 1;    
                    if (split[n] != String.Empty)    
                    {    
                        writer.Write(", ");    
                        writer.Write(split[n]);    
                    }    
                }    
            }    
            writer.Write("!");    
        }    
    }    

    internal class WelcomeLabelDesigner : ControlDesigner    
    {    
        protected WelcomeLabel parentControl;    

        public override void Initialize(IComponent component)    
        {    
            base.Initialize(component);    

            if (component is WelcomeLabel)    
            {    
                parentControl = (WelcomeLabel)component;    
            }    
        }    

        public override string GetDesignTimeHtml()    
        {    
            try    
            {    
                StringBuilder sb = new StringBuilder();    
                String url = parentControl.Page.ClientScript.GetWebResourceUrl(this.GetType(), "Samples.AspNet.CS.Controls.resources.images.WelcomeLabel.bmp");    
                sb.Append("<img alt="background image" src="" + url + ""  height="" + parentControl.Height + "px" width="" + parentControl.Width + "px"/>");    
                return sb.ToString();    
            } catch (Exception ex)    
            {    
                // Display the error in VS.net, in Design view    
                return String.Concat("<h3>Error</h3>Stack Trace:<br>", ex.StackTrace + "   " + ex.Message + " " + ex.InnerException);    
            }    
        }    
    }    
}    
问题回答

回归成像并不严格地被解释为html。 注:在GetDesigntimeHtml返回以下地点确实可行:

sb.Append("<img alt="background image" src="" + url + ""  Height="" + parentControl.Height + "" Width="" + parentControl.Width + ""/>");




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签