ASPX Control Inheritance Expert

5 posts, 1 answers
  1. Noah
    Noah avatar
    9 posts
    Member since:
    Dec 2008

    Posted 29 Dec 2014 Link to this post

    Hello,

    I need inherited versions of the RadButton and RadGrid.

    <telerik:RadButton ID="NewActionBtn" runat="server" NavigateUrl="New.aspx">
        <ContentTemplate>
            <span class="glyphicon glyphicon-2x glyphicon-plus" style="color: grey"></span><span class="glyphicon-2x"> Add</span>
        </ContentTemplate>
    </telerik:RadButton>

    Here is a sample of the RadButton currently in use.  It is use in an "Action" bar which is part of our UI.  I need to standardize the button so I only need to pass in the icon and button text for the Content Template.

    I also need a custom RadGrid.  I need to be able to standadize things like the page size, control location, export settings, etc across all grids on my site.

    If you have experience inheriting RadControls please contact me.

    Thanks
    -Noah
  2. Ivan Zhekov
    Admin
    Ivan Zhekov avatar
    540 posts

    Posted 01 Jan 2015 Link to this post

    Hi, Noah.

    If you want to standardize control settings, you can use Asp.Net themes (http://msdn.microsoft.com/en-us/library/0yy5hxdk(v=vs.140).aspx) and apply the theme to each grid you want it to.

    The button can be made into custom user control that exposes two properties or a server control. Do note that the second option will require at least one other class for the ITemplate instance.

    Regards,
    Ivan Zhekov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Noah
    Noah avatar
    9 posts
    Member since:
    Dec 2008

    Posted 05 Jan 2015 in reply to Ivan Zhekov Link to this post

    Hello,

    Thank you for the idea about themes, that looks like it will accomplish my goals. 

    Do you have a sample of the ITemplate class for the RadButton?

    Thanks
    -Noah
  5. Answer
    Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 06 Jan 2015 Link to this post

    Hi Noah,

    Please examine the Button - Add elements in RadButton online demo for details.

    Regards,
    Danail Vasilev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Noah
    Noah avatar
    9 posts
    Member since:
    Dec 2008

    Posted 29 Jan 2015 in reply to Danail Vasilev Link to this post

    Thanks Danail,

    Here was my final solution.

    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    namespace A3CommonControls
    {
        [DefaultProperty("Text")]
        [ToolboxData("<{0}:A3Button runat=server></{0}:A3Button>")]
        public class A3Button : RadButton
        {
            public string ButtonText;
            public string ButtonImage;
     
     
            protected override void Render(HtmlTextWriter writer)
            {
                base.ContentTemplate = new A3ButtonContentTemplate(ButtonImage, ButtonText);
                base.Render(writer);
            }
     
        }
     
     
        public class A3ButtonContentTemplate : ITemplate
        {
            public string Icon;
            public string Text;
     
            public A3ButtonContentTemplate(string icon, string text)
            {
                Icon = icon;
                Text = text;
            }
     
            void ITemplate.InstantiateIn(Control container)
            {
                var contentLiteral = new Literal();
                contentLiteral.ID = "radButtonContent";
                contentLiteral.Text = String.Format("<span class='glyphicon glyphicon-2x glyphicon-{0}' style='color: grey'></span><span class='glyphicon-2x'> {1}</span>", Icon, Text);
                container.Controls.Add(contentLiteral);
     
            }
        }
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017