• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

Angel----部落阁
Xcode10
博客园    首页    新随笔    联系   管理    订阅  订阅
用户控件(.ascx)与网页间(.aspx)如何传值的几种方法

1.aspx文件:
public void SetLabel(string str)
    {
        this.Label1.Text = str; ;
    }
ascx文件;
protected void Button1_Click(object sender, EventArgs e)
    {
        System.Web.UI.Page p = this.Page;
        Type pageType = p.GetType();
        MethodInfo mi = pageType.GetMethod("SetLabel");
        mi.Invoke(p, new object[] { "test!!!" });

    }

2. 在自定义控件中定义这个控件的属性
   public Control LabelText
 {
  get{return this.Label1.Text;}
 }

3用FindControl方法寻找
 Label lbl = (Label)WebUserControl1.FindControl("Label1");

posted on 2008-06-19 14:55  angelfeather  阅读(2242)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3