zoukankan      html  css  js  c++  java
  • asp.net 验证控件 attributes冲突解决

    我试了一个简单的页面  
      一个TextBox1和一个RequiredFieldValidator1   和一个   Button1  
       
       
       
      private   void   Page_Load(object   sender,   System.EventArgs   e)  
      {  
      //   在此处放置用户代码以初始化页面  
      if(!this.IsPostBack)  
      {  
        Button1.Attributes["onclick"]   =   "javascript:return   window.confirm('Are   you   sure?');";  
       
      }  
      }  
      private   void   Button1_Click(object   sender,   System.EventArgs   e)  
      {  
                this.Response.Write("进入..");  
      }  
       
      下周问题是:  
                                  如果我不加     Button1.Attributes["onclick"]   =   "javascript:return   window.confirm('Are   you   sure?');";  
      则在TextBox1为空的时候无法提交,现在验证控件起作用  
                                  如果我加上     Button1.Attributes["onclick"]   =   "javascript:return   window.confirm('Are   you   sure?');";  
      则在TextBox1为空的时候也可以提交,现在验证控件不起作用  
       
      请问为什么呢??怎样让验证控件起作用呢?? 

    解决办法:
    Button1.Attributes["onclick"]   =   "if(typeof(Page_ClientValidate)   ==   'function'){if(confirm('Are   you   sure?')){return   Page_ClientValidate();}else   {return   false;}}else{return   confirm('Are   you   sure?');}";

    根据我的业务需求,我是这样改的:
    this.btn_Add.Attributes["onclick"] = "if(typeof(Page_ClientValidate)  == 'function'){if(Page_ClientValidate()==true){return  CheckValue() ;}else   {return   false;}}else{return  CheckValue();}";
  • 相关阅读:
    php 加入即时推送功能
    Yii GridView::widget
    linux 文件文件夹操作
    一套一般般的前端框架 layui
    supervisor 与 yii定时任务 crontab的使用
    yii 国际化
    如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
    docker搭建lnmp环境
    docker搭建lnmp环境(问题,资料,命令)
    yii2 刷新缓存(刷新模型缓存)
  • 原文地址:https://www.cnblogs.com/wantingqiang/p/1582813.html
Copyright © 2011-2022 走看看