教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 c#获取用户控件中控件的ID的代码

c#获取用户控件中控件的ID的代码

发布时间:2015-10-24   编辑:jiaochengji.com
问题:用户控件中有个label控件,需要根据用户控件被引用后的ID值来未其赋值,请问如何才能在ASCX中得到引用后的用户控件ID?

问题:用户控件中有个label控件,需要根据用户控件被引用后的ID值来未其赋值,请问如何才能在ASCX中得到引用后的用户控件ID?

用户控件,将有可能被aspx或是masterPgae所应用。用户控件就是象打工仔,有可能被雇主聘用。每位打工仔都想赚钱,谁会给自己钱,也许不清楚;而雇主聘请人才或是投资,他只管付钱,付给谁也不一定清楚,因此Insus.NET在此创建一个接口,接口中有一个方法,是付钱。
 

复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for IPayable
/// </summary>
namespace Insus.NET
{
    public interface IPayable
    {
        void Pay(object value);
    }
}

打工仔(用户控件)没有钱用,就是去打工赚钱,也就是实作这个接口:
 

复制代码 代码如下:

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 InsusUserControl : System.Web.UI.UserControl,IPayable
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public void Pay(object value)
    {
        this.Label1.Text = value.ToString();
    }
}

接下来,是什么样的老板聘请到你呢,如果是page的,也就是说,用户控件被拉至aspx页面中。
 

复制代码 代码如下:

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 _Default : System.Web.UI.Page
{      
    protected void Page_Load(object sender, EventArgs e)
    {
        // 在老板发工资时,他要知道有谁努力工作,才付薪水。
        IPayable uc = (IPayable)this.InsusUserControl1;
        uc.Pay("$15k");
    }
}

您可能感兴趣的文章:
ExtJS设置与获取radio控件的选取状态
动态加载用户控件(整理)
asp.net的用户控件心得
jquery获取页面input控件所有text控件然后追加样式属性
asp.net 用户控件中图片与样式引用的问题
ASP.NET 2.0服务器控件开发
c#获取用户控件中控件的ID的代码
asp.net Textbox控件注册回车事件与触发按钮提交事件的实现方法
ASP.NET设计网络硬盘之上传文件
js代码获取TreeView控件选中节点的Text和Value

[关闭]
~ ~