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

Is it possible to extend WidgetBuilderBase?

3 Answers 147 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ross B.
Top achievements
Rank 1
Ross B. asked on 27 Nov 2013, 03:46 AM
Greetings,

I would like to extend a Kendo.Mvc.UI.Fluent builder in my own html helper method and would like to know the easiest way to do this. To use a very simple scenario, I have many @Kendo.Button components that optionally need to be hidden. Until now I have created HtmlHelper functions and send in my custom parameters for various controls. I would like to start extending the WidgetBuilder itself.

For example is something like this easy to accomplish:

public class MyButtonBuilder : Kendo.Mvc.UI.Fluent.ButtonBuilder
{
    public bool Visible { get; set; }
     
    public override void Render()
    {
        if(Visible==false)
            //Do something to return empty HTML
        else
            base.Render();
    }
}



Thanks

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 27 Nov 2013, 09:01 AM
Hi Ross,

You can try something like this:

public class MyButtonBuilder : ButtonBuilder
{
    public MyButtonBuilder(Button button) : base(button)
    {
    }
}
 
public static class MyExtensions
{
    public static MyButtonBuilder MyButton(this HtmlHelper helper)
    {
        return new MyButtonBuilder(helper.Kendo().Button().ToComponent());
    }
}


Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ross B.
Top achievements
Rank 1
answered on 27 Nov 2013, 03:40 PM
Hi Atanas and thanks for the quick reply.

I will use your examples to create widget's in the future. I am now struggling to find documentation or direction on which methods would need to be overridden to render the control as hidden or nothing. 

.ToHtmlString()?


In the snippet below
@HtmlHelper.ExtendedKendoButton().Name("btnTest").Icon("cancel").Visible(false)

What methods would I need to override to inspect a visible property and render HtmlRaw("") or some attribute that makes the markup invisible?


Thanks again!
0
Accepted
Atanas Korchev
Telerik team
answered on 27 Nov 2013, 03:47 PM
Hi,

It would have beenthe ToHtmlString method however it is not virtual. You can override Render though. Then you need to output your widget like this:

@{ 
Html.ExtendedKendoButton().Name("btnTest").Icon("cancel").Visible(false).Render();
}

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Ross B.
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ross B.
Top achievements
Rank 1
Share this question
or