最近做一個自定義控件,控件裏有一個隱藏的div,在設計時會把不整個頁面撐開,甚至是aspx在設計與html切換時會改變整個面頁的佈局,如何解決這個問題.自已搞了很久沒有搞定,後來在csdn裏請高手解決了.http://community.csdn.net/Expert/topic/4930/4930751.xml?temp=.9275324
在csdn提問之前我也在msdn裏找到了下面這個幫助,但由於比較急,沒有細看.呵呵,以後做事一定保持平靜,這樣可能會少走彎路.
還有,System.Web.UI.Design需要引進System.Design.dll
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
namespace WebControlDesignerExample
{
// This control designer offers designer verb menu commands
// that can alter the design time html provided for the
// System.Web.UI.Control this designer supports.
public class TextSizeWebControlDesigner : System.Web.UI.Design.ControlDesigner
{
// Whether to display the html of the associated
// control using a large heading text size.
private bool LargeText;
public TextSizeWebControlDesigner() : base()
{
LargeText = false;
}
// Provides a menu command to toggle the text size.
public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
DesignerVerbCollection dvc = new DesignerVerbCollection();
if( LargeText )
dvc.Add( new DesignerVerb("Reduce text size", new EventHandler(this.toggleTextSize)) );
else
dvc.Add( new DesignerVerb("Enlarge text size", new EventHandler(this.toggleTextSize)) );
return dvc;
}
}
// Returns the html to use to represent the control at design time.
public override string GetDesignTimeHtml()
{
string html = base.GetDesignTimeHtml();
if( LargeText )
return "<H1>"+html+"</H1>";
else
return "<H3>"+html+"</H3>";
}
// Event handler to toggle whether the html receives a large or
// small size heading markup tag.
private void toggleTextSize(object sender, EventArgs e)
{
if( LargeText )
LargeText = false;
else
LargeText = true;
this.IsDirty = true;
this.UpdateDesignTimeHtml();
}
}
// Simple text web control renders a text string.
// This control is associated with the TextSizeWebControlDesigner.
[DesignerAttribute(typeof(TextSizeWebControlDesigner), typeof(IDesigner))]
public class TextControl : System.Web.UI.WebControls.WebControl
{
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public TextControl()
{
text = "Test phrase";
}
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
}