Inheriting FormDecorator

5 posts, 1 answers
  1. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 17 May 2010 Link to this post

    Hi,
    I have a base page inheriting from System.Web.UI.Page and the rest of my pages inherit from this base page so I can manage security etc. in one place. What I wanted to know was whether I can place a FormDecorator on the base page so as to automatically control skins on all descendants from one place?
    It does not seem to work currently and I get errors as soon as I drop FormDecorator on the base page, something about "unable to cast RadformDecorator to ISkinnableControl".

    If this is not possible, any other ideas on how to achieve central control of skins would be great.
  2. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 17 May 2010 Link to this post

    Hello Al,

    You should be able to have a form decorator instance in your base page if you ensure that it is properly added:

    - the form decorator must be added after the ASP.NET AJAX script manager control.
    - both the script manager and the form decorator should be in the page form.

    You can try adding the decorator (and script manager) to the ASP.NET form (Page.Form property) in the onload event of your base page class. If that does not work, please post some sample code from your base class so we can test it.

    Sincerely yours,
    Lini
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 18 May 2010 Link to this post

    Thanks Lini,

    It seems that I had a versioning issue, after completely removing all versions of rad and re-installing Q1 2010 SP1 I can now add the form decorator just fine (I didn't have the net 4.0 binaries).

    I still have a question on the inheritance bit:
    1. - If I use a master page and place a scriptmanager and form decorator on the master, all child pages get decorated as expected - all ok.
    2. - If I do not use a master page and place a scriptmanager and form decorator on my custom page base class, no pages that inherit from this base class get decorated (in fact the form decorator is not visible in the base class at all). This kind of makes sense to me because the controls are in the body of the base class, not the inheriated class. Could you maybe give me an example of what you mean by "You can try adding the decorator (and script manager) to the ASP.NET form (Page.Form property) in the onload event of your base page class"?

    Do you think there is a better way to have one FormDecorator operating on multiple pages without using Master pages?
  5. Answer
    Lini
    Admin
    Lini avatar
    2144 posts

    Posted 21 May 2010 Link to this post

    Hi Al,

    Here is an example of a base page class with an overridden OnLoad method:

    public class BasePage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            var sm = System.Web.UI.ScriptManager.GetCurrent(Page);
            if (sm == null)
            {
                sm = new System.Web.UI.ScriptManager();
                Form.Controls.Add(sm);
            }
            var fd = new Telerik.Web.UI.RadFormDecorator();
            fd.ID = "rfd1";
            fd.Skin = "Black";
            Form.Controls.Add(fd);
        }
    }

    I don't think there is a better way to add a form decorator to all your pages other than the two already mentioned (master page, base page class).

    All the best,
    Lini
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 24 May 2010 Link to this post

    Thanks Lini, that worked perfectly.
    It is strange that it didn't work when dragging the form decorator from the toolbaox like all the other controls, perhaps there is a bug here?
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017