May 17, 2013, 3:14 PM
[CLOSED] Creating Custom Control From Ext.Net.Label in MVC 4.0
Hi,
I am trying to create custom properties in a custom control derived from Ext.Net.Label. I am able to create a custom control and able to access the inherent properties of Ext.NET, But when I try to add a new property(LabelText) in the derived class like @Html.Y().ExtLabel().LabelText("Hello")
, it's not showing up on the extension method. Here is the code.
Derived Class:
I am trying to create custom properties in a custom control derived from Ext.Net.Label. I am able to create a custom control and able to access the inherent properties of Ext.NET, But when I try to add a new property(LabelText) in the derived class like @Html.Y().ExtLabel().LabelText("Hello")
, it's not showing up on the extension method. Here is the code.
Derived Class:
namespace Ext.Net.Extn.Extensions
{
public partial class ExtLabel : Label
{
public ExtLabel() : base() { }
private string _LabelText;
//Custom Property
public string LabelText
{
get { return _LabelText; }
set { _LabelText = value; }
}
}
public partial class ExtLabel
{
//public Builder ToBuilder()
//{
// return new ControlFactory().ExtLabel();
//}
public class Builder : Builder<ExtLabel, Builder>
{
public Builder(ExtLabel label) : base(label) { }
//public Builder() : base(new ExtLabel()) { }
}
}
}
Extension: For accessing custom control under Y() extentionpublic class Y { }
public static class YExtensions
{
public static ControlFactory Y(this HtmlHelper helper)
{
return new ControlFactory { HtmlHelper = helper };
}
}
ControlFactory: For creating Builder class of tghe custom controlpublic ExtLabel.Builder ExtLabel()
{
return BuildControl<ExtLabel, ExtLabel.Builder>(new ExtLabel
{
ID = Guid.NewGuid().ToString("N"),
ViewContext = HtmlHelper != null ? HtmlHelper.ViewContext : null
});
}
Factory: Generic method for actually creating the builder class.public HtmlHelper _HtmlHelper { get; set; }
public TBuilder BuildControl<TControl, TBuilder>(TControl control)
{
return (TBuilder)Activator.CreateInstance(typeof(TBuilder), control);
}
The above aproach is working fine for
Last edited by Baidaly; Jun 12, 2013 at 6:06 PM.
Reason: [CLOSED]