Pee*_*ush 4 javascript c# asp.net
我在我的asp.net Web应用程序中遇到一个问题,我需要在点击" 更新"按钮时显示一个java脚本确认框,这符合我的要求.
目前我正在使用onclient点击
<asp:Button ID="btnCustomerUpdate" runat="server" CssClass="applybuttonstyle"
Text="Update" onclick="btnCustomerUpdate_Click"
OnClientClick="return confirm('Do you really want to update?');"/>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但问题是我还在我的表单字段上应用了一些验证控件,因此如果用户将任何字段留空并单击更新按钮,则它会显示javascript确认框和该表单字段下面的验证消息.
除非所有验证都通过,否则不应该显示确认框.
我希望这是因为我在客户端点击使用这个,所以请告诉我一个更好的解决方案.
提前致谢.
您可以Page_ClientValidate在自己的确认功能中使用来决定是否显示确认对话框.就像是:
function validateAndConfirm(message){
var validated = Page_ClientValidate('group1');
if (validated){
return confirm(message);
}
}
Run Code Online (Sandbox Code Playgroud)
在服务器上你会有类似的东西:
<asp:textbox id="TextBox1" runat="server"/>
<asp:requiredfieldvalidator ValidationGroup="group1"
ErrorText="Need to Fill in Value!"
ControlToValidate="TextBox1"
runat="server"/>
<asp:textbox id="TextBox2" runat="server"/>
<asp:requiredfieldvalidator ValidationGroup="group1"
ErrorText="Need to Fill in Value!"
ControlToValidate="TextBox2"
runat="server"/>
Run Code Online (Sandbox Code Playgroud)
您的按钮代码将更改为:
<asp:Button ID="btnCustomerUpdate" runat="server" CssClass="applybuttonstyle"
Text="Update" onclick="btnCustomerUpdate_Click" ValidationGroup="group1"
OnClientClick="return validateAndConfirm('Do you really want to update?');"/>
Run Code Online (Sandbox Code Playgroud)
显然,我无法测试这一点,但你明白了.
如果您将使用,Page_ClientValidate您可能会发现此SO问题很有用.
| 归档时间: |
|
| 查看次数: |
10632 次 |
| 最近记录: |