Is there anyway to pass an object to an usercontrol through the frontend tags? I have tried the following but it doesn't work.
Backend
public Range Range { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
// Popular channel range
Range Range = new Range()
{
Min = 0,
Max = 8
};
}
Frontend
<uc:PopularItems Range="<%=Range %>" runat="server" />
User controls are containers into which you can put markup and Web server controls. You can then treat the user control as a unit and define properties and methods for it. Custom controls. A custom control is a class that you write that derives from Control or WebControl.
In ASP.Net you need to register one tagprefix and then use the user control by tagprefix registered but in ASP.Net MVC using simple Thml. RenderPartial we can use the user control.
You can't use <%=
with a server control. You should use <%#
and databind:
Backend
[Bindable(true)]
public Range Range { get; set; }
Frontend
<uc:PopularItems ID="myControl" Range="<%# Range %>" runat="server" />
Backend of the page
if(! IsPostBack) {
myControl.DataBind();
// or, to bind each control in the page:
// this.DataBind();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With