如果页面开启就禁用,且需在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;
}
本文介绍了一种在网页加载过程中管理页面控件的方法。通过检查会话状态来决定是否重定向到登录页面,并根据条件禁用特定的输入字段。此外,还提供了一个通用的方法来批量启用或禁用多个控件。
1084

被折叠的 条评论
为什么被折叠?



