现在,我们有输入一些东西,再点击提交按钮,看一下代码如何走
首先是,在ValidatorOnLoad->ValidatorHookupControlID->ValidatorHookupControl函数中,文本框的
onchange事件被指向ValidatorOnChange,因此在调试时,第一次点击按钮时,先会激发ValidatorOnChange。
function ValidatorOnChange(event)
{
//如果没有设置事件的话,取window的事件?
if (!event)
event = window.event;
Page_InvalidControlToBeFocused = null;
var targetedControl;
//获取事件源控件
if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null))
targetedControl = event.srcElement;
else
targetedControl = event.target;
var vals;
//获取源控件的对应验证控件
if (typeof(targetedControl.Validators) != "undefined")
vals = targetedControl.Validators;
else
{
if (targetedControl.tagName.toLowerCase() == "label")
{
//htmlFor?DHMTL中有,不是微软自己高兴乱加的
targetedControl = document.getElementById(targetedControl.htmlFor);
vals = targetedControl.Validators;
}
}
var i;
//对所有验证控件都进行验证
for (i = 0; i < vals.length; i++)
ValidatorValidate(vals[i], null, event);
//更新网页的验证情况
ValidatorUpdateIsValid();
}
{
//如果没有设置事件的话,取window的事件?
if (!event)
event = window.event;
Page_InvalidControlToBeFocused = null;
var targetedControl;
//获取事件源控件
if ((typeof(event.srcElement) != "undefined") && (event.srcElement != null))
targetedControl = event.srcElement;
else
targetedControl = event.target;
var vals;
//获取源控件的对应验证控件
if (typeof(targetedControl.Validators) != "undefined")
vals = targetedControl.Validators;
else
{
if (targetedControl.tagName.toLowerCase() == "label")
{
//htmlFor?DHMTL中有,不是微软自己高兴乱加的
targetedControl = document.getElementById(targetedControl.htmlFor);
vals = targetedControl.Validators;
}
}
var i;
//对所有验证控件都进行验证
for (i = 0; i < vals.length; i++)
ValidatorValidate(vals[i], null, event);
//更新网页的验证情况
ValidatorUpdateIsValid();
}
接着执行按钮的提交代码,执行的子程序前一部分验证功能与之前说的过程一样,列表如下:
WebForm_PostBackOptions
WebForm_DoPostBackWithOptions
Page_ClientValidate
ValidatorValidate
IsValidationGroupMatch
evaluationfunction=RequiredFieldValidatorEvaluateIsValid
ValidatorGetValue
ValidatorTrim
ValidatorUpdateDisplay
ValidatorUpdateIsValid
AllValidatorsValid
ValidationSummaryOnSubmit
当页面验证完成后,以后的代码就开始有差异了
if (validationResult)
{
//如果按钮有设置actionUrl,则网页将转向该位置
if ((typeof(options.actionUrl) != "undefined") &&
(options.actionUrl != null) &&
(options.actionUrl.length > 0))
theForm.action = options.actionUrl;
//如果按钮有trackFocus?,则执行?,这里没有所以跳过
if (options.trackFocus)
{
var lastFocus = theForm.elements["__LASTFOCUS"];
if ((typeof(lastFocus) != "undefined") && (lastFocus != null))
{
if (typeof(document.activeElement) == "undefined")
lastFocus.value = options.eventTarget;
else
{
var active = document.activeElement;
if ((typeof(active) != "undefined") && (active != null))
{
if ((typeof(active.id) != "undefined") &&
(active.id != null) &&
(active.id.length > 0))
lastFocus.value = active.id;
else if (typeof(active.name) != "undefined")
lastFocus.value = active.name;
}
}
}
}
}
//如果按钮有设clientSubmit,则直接提交,这里没有
if (options.clientSubmit)
__doPostBack(options.eventTarget, options.eventArgument);
{
//如果按钮有设置actionUrl,则网页将转向该位置
if ((typeof(options.actionUrl) != "undefined") &&
(options.actionUrl != null) &&
(options.actionUrl.length > 0))
theForm.action = options.actionUrl;
//如果按钮有trackFocus?,则执行?,这里没有所以跳过
if (options.trackFocus)
{
var lastFocus = theForm.elements["__LASTFOCUS"];
if ((typeof(lastFocus) != "undefined") && (lastFocus != null))
{
if (typeof(document.activeElement) == "undefined")
lastFocus.value = options.eventTarget;
else
{
var active = document.activeElement;
if ((typeof(active) != "undefined") && (active != null))
{
if ((typeof(active.id) != "undefined") &&
(active.id != null) &&
(active.id.length > 0))
lastFocus.value = active.id;
else if (typeof(active.name) != "undefined")
lastFocus.value = active.name;
}
}
}
}
}
//如果按钮有设clientSubmit,则直接提交,这里没有
if (options.clientSubmit)
__doPostBack(options.eventTarget, options.eventArgument);
执行完,好象没什么大事发生。
返回主页面,进行正式的提交。也是执行:WebForm_OnSubmit->ValidatorOnSubmit->ValidatorCommonOnSubmit。只是返回值为true。激发action,真正的提交给服务器。
结束