zoukankan      html  css  js  c++  java
  • 获取用户控件中控件的ID

      用户控件中有个label控件,需要根据用户控件被引用后的ID值来未其赋值,请问如何才能在ASCX中得到引用后的用户控件ID
    这是来自某论坛的问题,不过标题Insus.NET有所更改。

    用户控件,将有可能被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");
        }
    }
  • 相关阅读:
    Export excel的终级解决方案
    Power Designer 常见问题
    正反向数据库及生成设计报告
    寻求最佳开发模式,免得落得“精”尽人亡
    XmlNode与XmlElement的区别总结
    软件版本的定义:
    我发现博客园一个很严重的问题
    sql 行转列的终极写法
    js 自定义 $ 选择器
    可持续集成环境相关文章
  • 原文地址:https://www.cnblogs.com/insus/p/2769026.html
Copyright © 2011-2022 走看看