This is a mobile optimized page that loads fast, if you want to load the real page, click this text.

Gọi hàm C#

lucmtg3000

Gà con
mình có 3 hàm như dưới sau khi bấm nút save, nếu textbox không ghi gì thì sẽ gọi hàm callabelNotBpcode() mà nó không hiển thị thông báo ae ạ xem lỗi ở đâu mà ko hiển thị đc:
public void callabelNotBpcode()
{
ClassLabel lbNoteBpcode = new ClassLabel("Please enter a valid BP Code", 100, 128);
lbNoteBpcode.ForeColor = Color.Red;
Controls.Add(lbNoteBpcode);
}

public void txtBpcode_Validating(object sender, CancelEventArgs e)
{
callabelNotBpcode();
MyTextBox txtBpcode = (MyTextBox)sender;
if (txtBpcode.Text == "Input Code" || txtBpcode.Text == "")
{
txtBpcode.BorderColor = Color.Red;
errorProvider1.SetError(txtBpcode, "");
return;
}
else
{
//To clear the validation error
this.errorProvider1.SetError(txtBpcode,"");
txtBpcode.BorderColor = Color.LightGray;
}

}

private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (this.ValidateChildren())
{
//Here the form is in valid state
//Do what you need when the form is valid
}
else
{

var listOfErrors = this.errorProvider1.ContainerControl.Controls.Cast<Control>()
.Select(c => this.errorProvider1.GetError(c))
.Where(s => !string.IsNullOrEmpty(s))
.ToList();

}
}catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}
 

baoenzo

Búa Đá Đôi
Mấy cái này thì đặt debug mà xem đi bạn. Đăng code thế này khó nhìn quá