原谅我,但我对整个编程工作还不熟悉,而且我一直无法找到更具体/直接的答案。
我有一个我在asp.net C#中构建的表单,用于从数据库中提取数据。存储过程运行并自动填充一系列文本框,如果它找到任何内容 - 用户的姓名,电子邮件,电话号码等。然后禁用填充字段,这样用户就无法更改&#39被带来了;如果需要,空字段仍然可供用户完成。
但是,当用户提交表单时 - 如果验证失败 - 以前禁用的字段(带有数据的字段)正在启用,允许用户在需要时覆盖它们 - 但我需要防止这种情况发生;无论如何要保持那些被我的原始数据禁用的字段在返回时重新启用?
我禁用了按钮点击事件中的字段。这些字段在页面加载时被禁用:
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = title;
Literal formHeader = (Literal)this.Master.FindControl("formHeader");
formHeader.Text = "Travel Booking Request";
if (!Page.IsPostBack)
{
Load_FormDetails();
Load_SeatingPreference();
Load_UserResponses();
Load_UndergroundTravelZones();
}
}
protected void Load_FormDetails()
{
string userName = "";
string userPhone = "";
string userTitle = "";
string userEmail = "";
List<KeyValuePair<string, string>> userDetails = Class1.GetUserDetails();
var name = userDetails.Where(kvp => kvp.Key == "UserDisplayName").Select(kvp => kvp.Value).First();
userName = name.ToString();
var phone = userDetails.Where(kvp => kvp.Key == "UserLandline").Select(kvp => kvp.Value).First();
userPhone = phone.ToString();
var jobtitle = userDetails.Where(kvp => kvp.Key == "UserJobTitle").Select(kvp => kvp.Value).First();
userTitle = jobtitle.ToString();
var email = userDetails.Where(kvp => kvp.Key == "UserEmail").Select(kvp => kvp.Value).First();
userEmail = email.ToString();
txtUserName.Text = userName;
if (txtUserName.Text != "")
{
txtUserName.Enabled = "false";
}
txtUserPhoneNumber.Text = userPhone;
if (txtUserPhoneNumber.Text != "")
{
txtUserPhoneNumber.Enabled = "false";
}
txtUserJobTitle.Text = userTitle;
if (txtUserJobTitle.Text != "")
{
pfptxtUserJobTitle.Enabled = "false";
}
txtUserEmail.Text = userEmail;
if (txtUserEmail.Text != "")
{
txtUserEmail.Enabled = "false";
}
}
答案 0 :(得分:0)
在.aspx页面的文本框定义中添加Readonly = true或add enabled = false。
它会永久禁用文本框