[英]Error when creating a panel dynamically in ASP.NET
我正在创建一个面板以填充一些控件但我在尝试编写其属性时遇到错误。
我的代码:
public partial class _Default : System.Web.UI.Page
{
Panel pbx;
protected void Page_PreInit(object sender, EventArgs e)
{
//Create a Dynamic Panel
pbx = new Panel();
pbx.ID = "pbx";
pbx.BorderWidth = 1;
pbx.Width = 300;
this.form1.Controls.Add(pbx);
}
//some other functions
}
Visual Studio 2012强调“ID”,“BorderWidth”和“Width”字样,因此我无法运行该项目。 其中一个错误是这样的:
'simplePanel.Panel'不包含'BorderWidth'的定义,并且没有扩展方法'BorderWidth'接受类型'simplePanel.Panel'的第一个参数可以找到(你是否缺少using指令或汇编引用?)
编辑:我可以创建一个没有问题的文本框或标签。 但不是专家组。
有一个名为simplePanel.Panel
的类与System.Web.UI.WebControls.Panel
冲突(我假设你正在尝试引用它)。 如果您_Default
类是simplePanel
命名空间为好,那么你就需要完全限定的引用Panel
,使编译器知道哪一个你的意思是:
public partial class _Default : System.Web.UI.Page
{
System.Web.UI.WebControls.Panel pbx;
protected void Page_PreInit(object sender, EventArgs e)
{
//Create a Dynamic Panel
pbx = new System.Web.UI.WebControls.Panel();
设置宽度如下:
pbx.Width = new Unit("300px");
它将帮助您了解情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.