控件禁用:readonly、enabled、disabled

如果页面开启就禁用,且需在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;
    }

你可能感兴趣的:(session,object,null)