分享

控件禁用:readonly、enabled、disabled

 绚爷好人图书馆 2014-07-14

如果页面开启就禁用,且需在page_loaded中加载,就需要这样写


    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            if (Session["LoginUser"] == null)
            {
                Response.Redirect("../Login.aspx");
                return;
            }
            else
            {
                txt_datetime.Attributes.Add("ReadOnly", "ReadOnly");
                txt_carNumber.Attributes.Add("disabled", "true");

            }

        }
    }

 

 

也可以在方法中写:

    /// <summary>
    /// 页面控件的可用性
    /// </summary>
    /// <param name="result">true:可用;false:禁用</param>
    private void controlEnabled(bool result)
    {
        txt_gasolineCard.Enabled = result;
        txt_carNumber.Enabled = result;
        txt_firstBalance.Enabled = result;
        imgSel.Visible = result;
    }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多