网站的费用可以做无形资产,口腔网站设计图,济南建站都选企汇优先做后付,织梦网站图片怎么修改在开发Asp.net时#xff0c;我们会经常有应用MasterPage或是WebUserControl。这样会遇上一个问题#xff0c;需要在aspx去找MasterPage或是WebUserControl内的对象#xff0c;或是从aspx传值给它们。比如一个WebUserControl被aspx调用之后#xff0c;它产生的ID会随着aspx的…在开发Asp.net时我们会经常有应用MasterPage或是WebUserControl。这样会遇上一个问题需要在aspx去找MasterPage或是WebUserControl内的对象或是从aspx传值给它们。比如一个WebUserControl被aspx调用之后它产生的ID会随着aspx的环境而变化而不是一成不变的因为假如使用FindControl()寻找的话当ID发生变化在aspx 运行时会发生异常。下面就以一个WebUserControl来演示。 这个WebUserControl会放一个CheckBoxList控件当这个WebUserControl拉到aspx页面去时在asps.cs给这个WebUserControl内的CheckBoxList控件绑定数据源。 写一个接口类别IGetable IGetable using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI.WebControls;/// summary/// Summary description for IGetable/// /summarynamespace Insus.NET{ public interface IGetable { CheckBoxList GetControl(); }} WebUserControl实作上面这个接口 InsusUc using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Insus.NET;public partial class InsusUc : System.Web.UI.UserControl,IGetable{ protected void Page_Load(object sender, EventArgs e) { } public CheckBoxList GetControl() { return this.CheckBoxList1; }} 最后是页面aspx.cs为WebUserControl的CheckBoxList控件赋值 View Code private void Data_Binding() { CheckBoxList cbl ((IGetable)this.InsusUc1).GetControl(); cbl.DataSource ProductCode; cbl.DataTextField value; cbl.DataValueField key; cbl.DataBind(); } 程序运行时的效果 源程序下载地址http://download.cnblogs.com/insus/ASPDOTNET/InterfaceDemo.rar