foreach (Control control in ContentPlaceHolder1.Controls)
{
if(typeof(Control).Equals(Telerik.Web.UI.RadEditor))
{
label1.Visible = true; label1.Text = "dhchk";
// control.CssFiles.Add("~/styles/myStyle.css");
}
}错误;-
“Telerik.Web.UI.RadEditor”是“type”,它在给定的上下文中无效
另外,这是向radEditor控件添加CSS类的正确方式吗?
control.CssFiles.Add("~/styles/myStyle.css"); 我真的想添加3-4个自定义的classes..how来做到这一点吗?
我做错了什么?请使用help...thnx
哦,我还想知道我是否可以在我的母版页中添加一些javascript或其他东西来检测所有的radEditor控件并设置它们的css类?我对Javascript..how了解不多,这是可能的吗?我该怎么做呢?但首先,我希望在代码中设置css类,代码有什么问题?
编辑
@Geek..我试着像this..is一样打电话,对吗?
Control c = new Control();
DoSomething(c);现在它在方法中给出了这个错误:
找不到类型或命名空间名称'c‘(是否缺少using指令或程序集引用?)
编辑
我确实添加了这个名称空间“使用System.Web.UI.WebControls;”为什么会出现这个错误??
发布于 2010-11-03 13:23:38
它应该是
if(typeof(control).Equals(Telerik.Web.UI.RadEditor)您将其大写,因此指向.Net控件对象,而不是您的控件对象。
您还需要递归地迭代ContentPlaceHolder中的控件。您可以拥有包含控件的其他对象,但您的代码永远找不到它们。
protected void DoSomething(Control control)(
{
foreach (Control c in control.Controls)
{
if(typeof(c).Equals(Telerik.Web.UI.RadEditor))
{
Telerik.Web.UI.RadEditor rad = c as Telerik.Web.UI.RadEditor;
rad.CssClass = "MyStyle";
label1.Visible = true; label1.Text = "dhchk";
// control.CssFiles.Add("~/styles/myStyle.css");
}
else
{
DoSomething(c);
}
}
}现在我们已经找到了RadEditor控件,并为它们分配了MyStyle类。现在使用css对它们进行相应的样式设置。
https://stackoverflow.com/questions/4084232
复制相似问题