Is it possible to create a "RadStyleSheetManager" at the runtime in code behind ?

5 posts, 0 answers
  1. ba
    ba avatar
    3 posts
    Member since:
    Sep 2010

    Posted 13 Sep 2011 Link to this post

    Is it possible to create a <RadStyleSheetManager> control programmatically just with a code behind in the cs class ? In other words, without declare something in the aspx page ? And if yes is it possible to put it in a content place of a master page if the page is linked to a master page ? tx and regards for your help.
  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 14 Sep 2011 Link to this post

    Hi Ba,

    You can use the following code (used on a normal page):
    override void OnInit(EventArgs e) {
    // Every page should have a script manager and style sheet manager
        if (Page.Form != null) {
            if (RadStyleSheetManager.GetCurrent(Page) == null) {
                RadStyleSheetManager styleSheetManager = new RadStyleSheetManager();
                //styleSheetManager.StyleSheets.Add(new StyleSheetReference(""));
     
                Page.Form.Controls.AddAt(0, styleSheetManager);
             }
        }   
        base.OnInit(e);
    }

    The only requirement for this to work in Master/Content page setups is that the control must be added in the Form.

    I hope this helps.

    Regards,
    Simon
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ba
    ba avatar
    3 posts
    Member since:
    Sep 2010

    Posted 14 Sep 2011 Link to this post

    Thanks Simon,
    It's running perfect.
  5. Somnath
    Somnath avatar
    43 posts
    Member since:
    Jun 2012

    Posted 15 Sep 2011 Link to this post

    Hi  Simon,

    I am following the same approch to create a RadStyleSheetManager in code behind.
    But here I am adding the control in Header and it is working perfect. 

    Page.Header.Controls.Add(objStyleSheetManager);

    We are having the Master/Content page in application and the same code is working for them as well.

    My question is then why it is required to add RadStyleSheetManager control in Form.

    Thanks n Regards,
  6. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 20 Sep 2011 Link to this post

    Hi Ankit,

    Actually it can also be added in the <head>. The 'requirement' I mentioned was more of a convention rather than a real requirement. Please excuse me for misleading you.

    Best wishes,
    Simon
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017