假设 页面文件叫:A.aspx .
控件名称叫:b.ascx
A中可以写方法 事件和字段 属性。b中也可以做同样的动作。但是引用的时候要注意。除了各自对自己的元素的引用以外。更重要的是对页面元素和控件元素的引用。
A的code中可以这样引用b的成员。this.b1.*
b可以这样引用A的成员 this.page.*



































顺便说一下对文件遍历的操作
//遍历文件夹
publicvoidShowAllFile()
{
DirectoryInfoTheFolder=newDirectoryInfo(MapPath("~/img/"));
//文件夹
foreach(DirectoryInfoNextFolderinTheFolder.GetDirectories())
this.ListBox1.Items.Add(NextFolder.Name);
//文件
foreach(FileInfoNextFileinTheFolder.GetFiles())
this.ListBox2.Items.Add(NextFile.Name);
}
publicvoidShowAllFile()
{
DirectoryInfoTheFolder=newDirectoryInfo(MapPath("~/img/"));
//文件夹
foreach(DirectoryInfoNextFolderinTheFolder.GetDirectories())
this.ListBox1.Items.Add(NextFolder.Name);
//文件
foreach(FileInfoNextFileinTheFolder.GetFiles())
this.ListBox2.Items.Add(NextFile.Name);
}