【问题标题】:Is it possible to pass an object to usercontrol in front-end?是否可以在前端将对象传递给用户控件?
【发布时间】:2012-01-13 18:56:19
【问题描述】:

有没有通过前端标签将对象传递给用户控件?我尝试了以下方法,但它不起作用。

后端

   public Range Range { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        // Popular channel range
        Range Range = new Range() 
        { 
            Min = 0, 
            Max = 8 
        };
    }

前端

<uc:PopularItems Range="<%=Range %>" runat="server" />

【问题讨论】:

    标签: asp.net webforms user-controls


    【解决方案1】:

    您不能将&lt;%= 与服务器控件一起使用。您应该使用&lt;%# 和数据绑定:

    后端

       [Bindable(true)]
       public Range Range { get; set; }
    

    前端

    <uc:PopularItems ID="myControl" Range="<%# Range %>" runat="server" />
    

    页面后端

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多