Tôi có một trang, nơi tôi muốn đăng nhập mọi thông báo xác thực mà người dùng không đáp ứng được các yêu cầu của trường được liên kết.Tìm trình xác thực không thành công asp.net
Vấn đề là postback/nút bấm của tôi không bao giờ xảy ra (có thể do xác nhận clientide), và do đó việc ghi nhật ký không bao giờ diễn ra trước khi người dùng thực sự có mọi trường đúng (không có lỗi xác thực).
Nút Phương thức sự kiện nhấp chuột:
protected void btnNext_Click(object sender, EventArgs e)
{
Page.Validate();
if(Page.IsValid)
{
//code
}
else
{
foreach (IValidator validator in Validators)
{
if (!validator.IsValid)
{
PageValidatorErrors error = new PageValidatorErrors
{
WebsiteID = AppState.WebsiteID,
Page = Request.Url.AbsolutePath,
URL = Request.Url.ToString(),
UserIP = Tools.GetIP(),
ErrorMessage = validator.ErrorMessage,
CreatedDate = DateTime.Now
};
pageValidatorErrorsRep.insert(error);
}
}
}
}
Bất kỳ ý tưởng, làm thế nào tôi có thể đăng nhập theese tin nhắn?
Edit:
<script type="text/javascript">
function validatePage()
{
if (window.Page_IsValid != true)
{
//Page_Validators is an array of validation controls in the page.
if (window.Page_Validators != undefined && window.Page_Validators != null)
{
//Looping through the whole validation collection.
for (var i = 0; i < window.Page_Validators.length; i++)
{
window.ValidatorEnable(window.Page_Validators[i]);
//if condition to check whether the validation was successfull or not.
if (!window.Page_Validators[i].isvalid)
{
var errMsg = window.Page_Validators[i].getAttribute('ErrorMessage');
alert(errMsg);
}
}
}
}
}
</script>
Ồ, tôi thấy, bạn đang yêu cầu làm thế nào để móc vào các khách hàng javascript bên mà trình xác nhận asp.net phát ra. – MatthewMartin
cảm ơn cho mẫu vòng lặp validator, tôi đã chuẩn bị viết nó một mình :) – rdmptn