asp.net 验证控件RequiredFieldValidator与js冲突的解决


                        ControlToValidate="txtAtlasName" ErrorMessage="不能为空">不能为空

 

                        οnclick="btn_createAtlas_Click" CausesValidation="True" />

 

如上所示,RequiredFieldValidator用来验证textbox是否为空

 

protected void Page_Load(object sender, EventArgs e)
    {
        this.btn_createAtlas.Attributes.Add("onclick", "javascript:return window.confirm('确定创建吗?');");
    }

 

page_load里添加了button事件,但是在点击按钮后,并不会触发页面的RequiredFieldValidator的验证。那么修改如下:

 

 

1  将button的CausesValidation属性设置为false

                        οnclick="btn_createAtlas_Click" CausesValidation="false" />

 

2  button确认属性中加入Page_ClientValidate()判断

protected void Page_Load(object sender, EventArgs e)
    {
        this.btn_createAtlas.Attributes.Add("onclick", "javascript:if(Page_ClientValidate())   return window.confirm('确定创建吗?');");
    }

你可能感兴趣的:(.Net,c#,javascript)