扩展 ASP.NET 面板
我正在尝试创建一个新的服务控件来扩展 ASP.NET 面板。
然而,每当我使用面板时,div 等都会正确渲染。 但框中的输入仅为:[标题]
即:如果我这样做:
<cc1:RoundedCornerBox id="MyBox" BoxWidth="100" BoxHeight="200"> This is the content that should be displayeed </cc1:RoundedBox>
显示的全部内容是: [MyBox]
(在正确的框中)
这是我的代码:
[DefaultProperty("Text")]
[ToolboxData("<{0}:RoundedCornerBox runat=server></{0}:RoundedCornerBox>")]
public class RoundedCornerBox : System.Web.UI.WebControls.Panel
{
public int BoxWidth { get; set; }
public int BoxHeight { get; set; }
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? "[" + this.ID + "]" : s);
}
set
{
ViewState["Text"] = value;
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text);
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
base.RenderBeginTag(writer);
writer.Write("<div class=\"roundedcornr_lt\"></div>\n");
writer.Write("<div class=\"roundedcornr_top\" style=\"width:" + BoxWidth.ToString() + "px\"></div>\n");
writer.Write("<div class=\"roundedcornr_rt\"></div>\n");
writer.Write("<div class=\"clear\"></div>\n");
writer.Write("<div class=\"roundedcornr_lside\" style=\"height:" + BoxHeight.ToString() + "px\"></div>\n");
writer.Write("<div style=\"width:" + BoxWidth.ToString() + "px; height:" + BoxHeight.ToString() + "px; background:white; float:left\">\n");
}
public override void RenderEndTag(HtmlTextWriter writer)
{
base.RenderEndTag(writer);
writer.Write("</div>\n");
writer.Write("<div class=\"roundedcornr_rside\" style=\"height:" + BoxHeight.ToString() + "px\"></div>\n");
writer.Write("<div class=\"clear\"></div>\n");
writer.Write("<div class=\"roundedcornr_bl\"></div>\n");
writer.Write("<div class=\"roundedcornr_btm\" style=\"width:" + BoxWidth.ToString() + "px\"></div>");
writer.Write("<div class=\"roundedcornr_br\"></div>");
writer.Write("<div class=\"clear\"></div>\n");
}
I am trying to create a new Service Control extending the ASP.NET panel.
Howwever whenever I use my panel, the divs etc render correctly.
But the input in the box is only : [title]
ie: if i do:
<cc1:RoundedCornerBox id="MyBox" BoxWidth="100" BoxHeight="200"> This is the content that should be displayeed </cc1:RoundedBox>
all that is displayed is:
[MyBox]
(in a box that is correct)
This is my code:
[DefaultProperty("Text")]
[ToolboxData("<{0}:RoundedCornerBox runat=server></{0}:RoundedCornerBox>")]
public class RoundedCornerBox : System.Web.UI.WebControls.Panel
{
public int BoxWidth { get; set; }
public int BoxHeight { get; set; }
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? "[" + this.ID + "]" : s);
}
set
{
ViewState["Text"] = value;
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text);
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
base.RenderBeginTag(writer);
writer.Write("<div class=\"roundedcornr_lt\"></div>\n");
writer.Write("<div class=\"roundedcornr_top\" style=\"width:" + BoxWidth.ToString() + "px\"></div>\n");
writer.Write("<div class=\"roundedcornr_rt\"></div>\n");
writer.Write("<div class=\"clear\"></div>\n");
writer.Write("<div class=\"roundedcornr_lside\" style=\"height:" + BoxHeight.ToString() + "px\"></div>\n");
writer.Write("<div style=\"width:" + BoxWidth.ToString() + "px; height:" + BoxHeight.ToString() + "px; background:white; float:left\">\n");
}
public override void RenderEndTag(HtmlTextWriter writer)
{
base.RenderEndTag(writer);
writer.Write("</div>\n");
writer.Write("<div class=\"roundedcornr_rside\" style=\"height:" + BoxHeight.ToString() + "px\"></div>\n");
writer.Write("<div class=\"clear\"></div>\n");
writer.Write("<div class=\"roundedcornr_bl\"></div>\n");
writer.Write("<div class=\"roundedcornr_btm\" style=\"width:" + BoxWidth.ToString() + "px\"></div>");
writer.Write("<div class=\"roundedcornr_br\"></div>");
writer.Write("<div class=\"clear\"></div>\n");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要继承 Label,您会这样做:
不幸的是,没有“正常”方法来获取面板的内部文本,但这是一种解决方法:
您基本上要做的是,获取面板中的文本(它会自动被 ASP.NET 插入到 Literal 子控件中)并在没有 ViewState 数据时输出它。
If you would inherit Label, you would do it this way:
Unfortunately there is no "normal" way to get the inner text of a Panel, but this is a workaround:
What you basically do is, you take the text in your Panel (which automatically gets inserted into a Literal child control by ASP.NET) and output it if there is no ViewState data.
有一种更简单的方法可以做到这一点。
Panel
。OnInit()
方法中,将CssClass
属性设置为roundedbox
样式(或任何其他名称)。border-radius
。例如:
There is a much easier way to do this.
Panel
.OnInit()
method, set theCssClass
property to aroundedbox
style (or any other name).border-radius
.For example: