开发者

Trying to access telerik RadEditor controls in master page's code behind as follows...its giving some error

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

}

Error;-

'Telerik.Web.UI.RadEditor' is a 'type', which is not valid in the given 开发者_如何学JAVAcontext

Also, is this the correct way to add CSS class to radEditor controls ??

control.CssFiles.Add("~/styles/myStyle.css"); 

I actually wanna add 3-4 customized classes..how to do that?

What am I doing wrong ? Please help...thnx

oh and also I was wondering if I can add some javascript or something in my Master page that will detect the ALL the radEditor controls and set their css classes ? don't know much of Javascript..how can that be made possible? how do I go about that? but first I want css classes to be set in code behind..what's wrong with the code?

[EDIT]

@Geek..I tried calling like this..is it correct?

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

now its giving this error in the method:-

The type or namespace name 'c' could not be found (are you missing a using directive or an assembly reference?)

[EDIT]

I do have this namespace added "using System.Web.UI.WebControls;" why this error ??


it should be

  if(typeof(control).Equals(Telerik.Web.UI.RadEditor)

You have it capitalized, therefore pointing at the .Net Control object, not your control object.

You also need to recursively iterate through the controls in your ContentPlaceHolder. you could have other objects that have controls in them, but your code will never find them.

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

    }

}

So we've found the RadEditor controls now, and assigned them the MyStyle class. Style them accordingly with css now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜