zoukankan      html  css  js  c++  java
  • asp.net常用代码

    1.实现在按个删除按钮之前弹出一个确认窗口

      方法一:

      在Page_Load中添加删除按钮的特征:

      例如:btn_Dele.Attributes["onClick"] = "if(!confirm('确定要删除吗?')) return false;";

      方法二:

      写一个自定义组件

    此组件从标准button继承,但在提交之前显示提示框,依旧支持验证
    using System; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.ComponentModel; 

    namespace Keyss.WebControls 

        [ToolboxData("<{0}:Button runat=server></{0}:Button>")] 
        public class Button : System.Web.UI.WebControls.Button 
        { 
            protected static string _warningScript = "if(!window.confirm('{0}')) return false;"; 


            [Bindable(true),  
            Category("Appearance"),  
            DefaultValue("")]  
            public string WarningMessage 
            { 
                get  
                { 
                    object o = ViewState["_warningMessage"]; 
                    return o==null?string.Empty:o.ToString(); 
                }
                set  
                { 
                    ViewState["_warningMessage"] = value; 
                }
            }
             
            [ 
            Bindable(true), 
            Category("Behavior"), 
            DefaultValue(false) 
            ] 
            public bool EnableWarning 
            { 
                get  
                { 
                    object o = ViewState["_enableWarning"]; 
                    return o==null?false:(bool)o; 
                }
                set  
                { 
                    ViewState["_enableWarning"] = value; 
                }
            }

             
            protected override void OnInit(EventArgs e) 
            { 
                base.OnInit (e); 
                if(this.EnableWarning) 
                { 
                    string onClick = this.Attributes["onclick"]; 
                    if(onClick == null) 
                    { 
                        this.Attributes["onclick"] = string.Format(_warningScript,this.WarningMessage); 
                    }
                    else
                    { 
                        this.Attributes["onclick"] = string.Format(_warningScript,this.WarningMessage) + onClick; 
                    }
                }     
            }

        }
    }

    2.js设置DropDownList控件不可用

      <script type="text/javascript">
            function fun()
            {
                  var field1Text;
                  var objs = document.getElementById('field1');
                  field1Text=objs.options[objs.selectedIndex].text;
                  if(field1Text == '所有类别')
                  {
                    //disabled的值,当为false时表示可用,为true时则才是不可用
                    document.getElementById("field3").disabled = true;
                    document.getElementById("RadioButtonTr").disabled = true;
                   }
                   else
                   {
                        document.getElementById("field3").disabled = false;
                        document.getElementById("RadioButtonTr").disabled = false;
                   }
            }
         </script>

  • 相关阅读:
    我觉得总结的不错的entityFramework
    vs2013引入com组件后,发布时如何提取出dll文件
    win10创建扩展分区
    web.config配置
    mysql时间增加一年
    json介绍
    phpcms列表分页ajax加载更多
    phpcms批量更新内容页只更新一点就返回问题
    phpcms不能批量更新栏目页和内容页
    iis设置默认文档,提示web.config配置xml格式不正确
  • 原文地址:https://www.cnblogs.com/zuoguanglin/p/2378789.html
Copyright © 2011-2022 走看看