从母版页后面的代码访问 RadEditor 控件...它没有找到任何 radEditor 控件,当它存在时...出了什么问题?

发布于 2024-09-30 09:26:39 字数 1389 浏览 0 评论 0原文

它没有在我的方法母版页中的 if 块中执行语句

:-

页面加载事件:-

Control c = new Control();
DoSomething(c);

我的方法:-

 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);
                }

            }

        }

我的内容页面:-

    <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>

[编辑] 调试时确定..我点击了“c”,然后快速观看。 ..它说“名称'c'在当前上下文中不存在”(?!?!)怎么会这样?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

莫相离 2024-10-07 09:26:39

那么,母版页首先呈现,因此您无法从母版页访问任何内容页控件。您可以使用事件并将控制从内容传递到主

更新来实现此目的:
再次强调 - 从母版页访问用户控件是整个母版>内容设计中的缺陷。我能想到的最接近的事情是添加静态函数

public static void AddDesign(RadEditor obj)
{
...
}

,然后从用户控件的 Page_Load 调用该函数

MASTER_PAGE_CLASS_NAME.AddDesign(RadEditor1);

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);
迷路的信 2024-10-07 09:26:39

好吧,我不确定,您可以像这样访问页面中的控件。

首先:该编辑器可能应该在某个面板(或其他容器)中,所以我应该看起来像这样:

<asp:Panel ID="pnl1" runat="server">
    <telerik:RadEditor ID="Editor1" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server" />
    <telerik:RadEditor ID="Editor2" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server" />
</asp:Panel>

然后尝试这个:

protected void Page_Load(object sender, EventArgs e)
{
    foreach (Controls c in pnl1.Controls)
    {
         if (c is Telerik.Web.UI.RadEditor)
         {
              // do you stuff ...
         }
    }
}

Well, I'm not sure, you can access controls in page like this.

At first: that editor should be probably in some Panel (or some other container), so i should look like this:

<asp:Panel ID="pnl1" runat="server">
    <telerik:RadEditor ID="Editor1" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server" />
    <telerik:RadEditor ID="Editor2" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins=false runat="server" />
</asp:Panel>

Then try this:

protected void Page_Load(object sender, EventArgs e)
{
    foreach (Controls c in pnl1.Controls)
    {
         if (c is Telerik.Web.UI.RadEditor)
         {
              // do you stuff ...
         }
    }
}
初懵 2024-10-07 09:26:39

您应该改变一些事情并从内容控件中调用 MasterPage 方法。

在母版页中添加方法:

public void DoSomething(Telerik.Web.UI.RadEditor rad)
{
    label1.Visible = true; label1.Text = "dhchk";
    rad.CssFiles.Add("~/styles/myStyle.css"); 
    rad.CssFiles.Add("~/styles/myStyle2.css");
    rad.CssFiles.Add("~/styles/myStyle3.css");         
}

从页面/内容控件中的适当事件调用该函数。例如 Page.Load、Editor1.Load 等

Master.DoSomething(Editor1);

更新

从母版页,您应该在内容控件中搜索子控件

ContentPlaceHolder1.FindControl("Editor1");

,或者您可以尝试以下操作:

foreach (Control c in ContentPlaceHolder1.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);
      }

 }

You should change things around and call your MasterPage method from the content control.

In your masterpage add the method:

public void DoSomething(Telerik.Web.UI.RadEditor rad)
{
    label1.Visible = true; label1.Text = "dhchk";
    rad.CssFiles.Add("~/styles/myStyle.css"); 
    rad.CssFiles.Add("~/styles/myStyle2.css");
    rad.CssFiles.Add("~/styles/myStyle3.css");         
}

Call the function from an appropriate event in your page/content control. eg Page.Load, Editor1.Load etc

Master.DoSomething(Editor1);

Update

From the masterpage, you should search for child controls in the Content controls

ContentPlaceHolder1.FindControl("Editor1");

or you could try something like:

foreach (Control c in ContentPlaceHolder1.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);
      }

 }
人疚 2024-10-07 09:26:39

母版页的加载和渲染事件在内容页的加载和渲染事件之后触发(如此处)。因此,在这两个事件被触发时,内容页面中的控件应该可用?

The load and render events of the master page are fired after those of the content page (as said here). Hence the controls in the content page should be available by the time these two events are fired?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文