RequiredFieldValidator + OnClientClick issue
来源:互联网 发布:centos mariadb 配置 编辑:程序博客网 时间:2024/05/16 05:48
JS script
function ConfirmMe()
{
return confirm("Do you want to proceed?");
}
ASPX
<asp:TextBox id="txtName" runat="server"/>
<asp:Button id="btnSubmit" OnClientClick="return ConfirmMe()" Text="Submit" runat="server"/>
Well, that is pretty straightforward. BUT, it goes weird when you have a validator control (eg. RequiredFieldValidator) that is used to validate the "txtName" textbox server control. For instance,
<asp:TextBox id="txtName" runat="server"/>
<asp:RequiredFieldValidator id="rq1" ControlToValidate="txtName" ErrorMessage="Name cannot be blank" Display="Dynamic" runat="server"/>
<asp:Button id="btnSubmit" OnClientClick="return ConfirmMe()" Text="Submit" runat="server"/>
Whenever you press the button with no textbox value, the client-side confirmation dialog will be invoked first before the validator message is able to show up. This isn't what we expected it to behave. I tried several ways to overcome this problem, including using CLIENT CALLBACK, disabling the CauseValidation, but it failed. Finally, I was able to find a solution by adding JUST ONE line in the JS script.
function ConfirmMe()
{
if(Page_ClientValidate())
return confirm('Do you want to proceed?');
return false;
}
Another discovery today !
function ConfirmMe()
{
return confirm("Do you want to proceed?");
}
ASPX
<asp:TextBox id="txtName" runat="server"/>
<asp:Button id="btnSubmit" OnClientClick="return ConfirmMe()" Text="Submit" runat="server"/>
Well, that is pretty straightforward. BUT, it goes weird when you have a validator control (eg. RequiredFieldValidator) that is used to validate the "txtName" textbox server control. For instance,
<asp:TextBox id="txtName" runat="server"/>
<asp:RequiredFieldValidator id="rq1" ControlToValidate="txtName" ErrorMessage="Name cannot be blank" Display="Dynamic" runat="server"/>
<asp:Button id="btnSubmit" OnClientClick="return ConfirmMe()" Text="Submit" runat="server"/>
Whenever you press the button with no textbox value, the client-side confirmation dialog will be invoked first before the validator message is able to show up. This isn't what we expected it to behave. I tried several ways to overcome this problem, including using CLIENT CALLBACK, disabling the CauseValidation, but it failed. Finally, I was able to find a solution by adding JUST ONE line in the JS script.
function ConfirmMe()
{
if(Page_ClientValidate())
return confirm('Do you want to proceed?');
return false;
}
Another discovery today !
- RequiredFieldValidator + OnClientClick issue
- 解决Button的OnClientClick与RequiredFieldValidator的问题
- 解決Button的OnClientClick和RequiredFieldValidator的冲突问题
- RequiredFieldValidator
- OnClientClick
- issue
- issue
- issue
- 验证RequiredFieldValidator
- RequiredFieldValidator验证
- RequiredFieldValidator控件
- OnClientClick 属性
- OnClientClick用法
- RequiredFieldValidator控件无效时
- 验证控件介绍--RequiredFieldValidator
- RequiredFieldValidator 控件介绍
- FCKEditor使用RequiredFieldValidator验证
- Validation服务器控件:RequiredFieldValidator
- 不要重复DAO!使用Hibernate 和Spring AOP 构建泛型类型安全的DAO
- 测试数据的添加
- Avalon学习
- 人生的35个好习惯
- Tmodel如何理解
- RequiredFieldValidator + OnClientClick issue
- showModalDialog窗体的提交问题。
- 使用 HibernateTemplate 实现分页查询
- 通过WEB链接打开QQ窗体,实现与陌生人交谈的目的
- 表格中当英文等过长时把表格扩大问题
- Error1Operator '+' cannot be applied to operands of type 'string' and 'method group'
- linux下汇编调试
- C#验证控件CustomValidator字数限制函数
- 简单网管协议代理 SNMP PROXY系统设计