为了账号安全,请及时绑定邮箱和手机立即绑定

获取用户控件中控件的ID

标签:
JavaScript

“  用户控件中有个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");
    }
}复制代码

 

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消