从主页的代码访问RadEditor控件...它没有找到任何radEditor控件,当它有什么错误? [英] Accessing RadEditor control from master page's code behind...its not finding any radEditor control when it is there..whats wrong?
问题描述
它在我的方法中未在if块中执行语句
主页: -
页面加载事件: -
控制c = new Control();
DoSomething(c);
我的方法: -
protected void DoSomething(控制控制)(
{
foreach(Control c in control.Controls)
{
if c).Equals(Telerik.Web.UI.RadEditor))
{
Telerik.Web.UI.RadEditor rad = c Telerik.Web.UI.RadEditor;
label1.Visible = true; label1.Text =dhchk;
rad.CssFiles.Add(〜/ styles / myStyle.css);
rad.CssFiles.Add(〜/ styles / myStyle2.css);
rad.CssFiles.Add(〜/ styles / myStyle3.css);
}
else
{
DoSomething ;
}
}
}
我的内容页面: -
< asp:Content ID =Content2ContentPlaceHolderID =ContentPlaceHolder1Runat =服务器>
< telerik:RadEditor ID =Editor1EnableEmbeddedBaseStylesheet =falseEnableEmbeddedSkins = false runat =server>
< / telerik:RadEditor>
< telerik:RadEditor ID =Editor2EnableEmbeddedBaseStylesheet =falseEnableEmbeddedSkins = false runat =server>
< / telerik:RadEditor>
在调试时确定。rt点击c ...它说当前上下文中不存在'c'这个名字。
解决方案好吧,母版页首先呈现,所以您不能从母版页访问任何内容页控件。
udpate:
再次 - 从母版页访问用户控件是有缺陷的整体主 - >内容设计。我可以想象的最接近的事情是添加静态函数public static void AddDesign(RadEditor obj)
{
...
}
然后调用用户控件的Page_Load函数
MASTER_PAGE_CLASS_NAME.AddDesign(RadEditor1);
Its not executing statements in if block in my method
Master Page:-
page load event:-
Control c = new Control(); DoSomething(c);
My method:-
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; label1.Visible = true; label1.Text = "dhchk"; rad.CssFiles.Add("~/styles/myStyle.css"); rad.CssFiles.Add("~/styles/myStyle2.css"); rad.CssFiles.Add("~/styles/myStyle3.css"); } else { DoSomething(c); } } }
my content page:-
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <telerik:RadEditor ID="Editor1" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server"> </telerik:RadEditor> <telerik:RadEditor ID="Editor2" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server"> </telerik:RadEditor>
[EDIT] ok when debugging..I rt clicked "c" and then Quick watch...it says "The name 'c' does not exist in the current context" (?!?!) how so ?
解决方案Well, the Master page renders first so you won't have access from the master page to any of the content page controls. You can achive this using events and passing the control from the content to the master
udpate: Again - Accessing user controls from the master page is flaw in the whole master->content design. the closest thing I can imagine is adding static function
public static void AddDesign(RadEditor obj) { ... }
and then call the function form the Page_Load of the user control
MASTER_PAGE_CLASS_NAME.AddDesign(RadEditor1);
这篇关于从主页的代码访问RadEditor控件...它没有找到任何radEditor控件,当它有什么错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!