This is a migrated thread and some comments may be shown as answers.

ASPX Control Inheritance Expert

4 Answers 44 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Noah
Top achievements
Rank 2
Noah asked on 29 Dec 2014, 08:58 PM
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

4 Answers, 1 is accepted

Sort by
0
Ivan Zhekov
Telerik team
answered on 01 Jan 2015, 11:04 AM
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.

 
0
Noah
Top achievements
Rank 2
answered on 05 Jan 2015, 10:24 PM
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
0
Accepted
Danail Vasilev
Telerik team
answered on 06 Jan 2015, 12:41 PM
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.

 
0
Noah
Top achievements
Rank 2
answered on 29 Jan 2015, 05:33 PM
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);
 
        }
    }
}
Tags
General Discussions
Asked by
Noah
Top achievements
Rank 2
Answers by
Ivan Zhekov
Telerik team
Noah
Top achievements
Rank 2
Danail Vasilev
Telerik team
Share this question
or