Is it possible to pass an object to usercontrol in an interface?

Is it possible to pass an object to user control through frontend tags? I tried the following, but it does not 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" /> 
+4
source share
1 answer

You cannot 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 page

  if(! IsPostBack) { myControl.DataBind(); // or, to bind each control in the page: // this.DataBind(); } 
+11
source

Source: https://habr.com/ru/post/1390897/


All Articles