you have to know about how to create user defined control.

来源:互联网 发布:单片机培训 编辑:程序博客网 时间:2024/06/05 15:25

You want to create dynamic user control in you C# code. One thing you must know is, you must register your control in your aspx file. you must add a sentence like this,

<%@ Register TagPrefix="Acme" TagName="Message" Src="~/ascx/FileDisplayFolder.ascx" %>

or else, you can't use the code to covert the control type. You can get only a usercontrol type. You can't use properties you created in your user control. that is awlful, you can't pass values to it.

if you registered your user control, you can create the control like this,

ascx_FileDisplayFolder Ctr = (ascx_FileDisplayFolder)Page.LoadControl("../ascx/FileDisplayFolder.ascx"); //加载控件
            Ctr.FolderName = folderName;
            contentMainBody.Controls.Add(Ctr); 

That's it!!!!!