gpt4 book ai didi

c# - 查找失败的验证器 asp.net

转载 作者:太空狗 更新时间:2023-10-29 17:55:09 25 4
gpt4 key购买 nike

我有一个页面,我想在其中记录用户未能满足相关字段要求的每条验证消息。

问题是我的回发/按钮点击从未发生(可能是因为客户端验证),因此在用户实际正确输入每个字段(无验证错误)之前,日志记录从未发生。

按钮点击事件方法:

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);
}
}
}
}

任何想法,我如何记录这些消息?

编辑:

<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>

最佳答案

这是解决方案的一部分,您可以通过在客户端调用它来获取 validates/true false:

http://razeeb.wordpress.com/2009/01/11/calling-aspnet-validators-from-javascript/

function performCheck()
{

if(Page_ClientValidate())
{

//Do something to log true/ false
}

}

关于c# - 查找失败的验证器 asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13382823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com