zoukankan      html  css  js  c++  java
  • 验证控件网页代码分析3

    现在,我们有输入一些东西,再点击提交按钮,看一下代码如何走
    首先是,在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();
    }

    接着执行按钮的提交代码,执行的子程序前一部分验证功能与之前说的过程一样,列表如下:
    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);

    执行完,好象没什么大事发生。

    返回主页面,进行正式的提交。也是执行:WebForm_OnSubmit->ValidatorOnSubmit->ValidatorCommonOnSubmit。只是返回值为true。激发action,真正的提交给服务器。
    结束

  • 相关阅读:
    c++智能指针的一些文章
    c++ template(8)模版多态
    空指针赋值分区
    windbg调试命令
    c++ template(5)模板实战
    GetStockObject 理解
    c++ template(6)模板术语
    c++ template(71)模板参数声明
    DirectDraw教程资料
    c++ template(9)trait和Policy
  • 原文地址:https://www.cnblogs.com/yzx99/p/1170750.html
Copyright © 2011-2022 走看看