ITPub博客

首页 > IT职业 > IT职场 > 为用户控件(UserControl)写属性

为用户控件(UserControl)写属性

IT职场 作者:jhere 时间:2021-09-09 09:48:11 0 删除 编辑

用户控件(UserControl)写属性的写法,如类别属性写法没有两样。参考代码:

InsusUserControlusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class InsusUserControl : System.Web.UI.UserControl
{
    public string DataKey
    {
        get
        {
            if (ViewState["DataKey"] != null)
            {
                return ViewState["DataKey"].ToString();
            }
            return string.Empty; //或设置一个默认值。
        }
        set
        {
            ViewState["DataKey"] = value;
        }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
}

 

当这个用户控件拉到aspx页面上去时,就可以直接为这个属性赋值了。

图片描述

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4022/viewspace-2812682/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-17

  • 博文量
    81
  • 访问量
    655