在aspx文件中调用ascx用户自定义控件的属性

   我们使用以下的方法来做:首先先定义自定义控件 *.ascx

public class yourcontrol : System.Web.UI.UserControl

{

    pravite string _Mytext

    public string Mytext

    {

         get{ ... }

         set{ ... }

    }

}

    

在调用它的 .aspx文件中:

首先要注册自定义控件,注册的语句要写到页面的上方(属于页面指令的位置。   )

<%@ Register TagPrefix="uc1" TagName="yourcontrol" Src="yourcontrol.ascx"%>

然后在aspx文件中使用:

<uc1:yourcontrol ID="yourControl1" runat="server"></前缀:控件标签名>

使用自定义控件的属性在 .aspx.cs文件中:

protected yourControl yourcontrol1;

yourcontrol1.Mytext = "";

posted @ 2011-05-11 10:28  茶海  阅读(1032)  评论(0编辑  收藏  举报