如何在按钮单击时验证文本框 [英] how to validate textboxes on button click

查看:153
本文介绍了如何在按钮单击时验证文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框,两个requiredfieldvalidator和两个按钮。我想当我点击button1时,只有textbox1应该被验证。当点击button2时,textbox2应该被验证。任何人都可以告诉我我该怎么做。

请帮助

i have two textbox, two requiredfieldvalidator and two buttons. i want to when i click on button1 only textbox1 should be validate. and when click on button2 textbox2 should be validate. can anyone tell me how can i do this.
please help

推荐答案

使用验证组

指定验证组 [ ^ ]

为button1和requiredfieldvalidator1设置相同的验证组,为另一个验证组设置button2和requiredfieldvalidator2
use Validation Groups
Specifying Validation Groups[^]
set same validation group for button1 and requiredfieldvalidator1 and another validation group for button2 and requiredfieldvalidator2


使用 ValidationGroup 属性

use ValidationGroup Property
    <asp:requiredfieldvalidator id="Req9" runat="server"  ValidationGroup="a"
                    ErrorMessage="Enter PINno"></asp:requiredfieldvalidator>  
 
     <asp:requiredfieldvalidator id="Req10" runat="server" controltovalidate="TextBox2" ValidationGroup="b"
                    ErrorMessage="Enter PINno"></asp:requiredfieldvalidator> 
 
<asp:button id="btnsubmit" runat="server" ValidationGroup="a" 
                     Text="Button1" onclick="btnsubmit_Click1"/>  
 
<asp:button id="btnsubmit1" runat="server" ValidationGroup="b" 
                     Text="Button2" onclick="btnsubmit1_Click1" />







将带有Button1和Textbox2的Textbox1与Button2分组




Group the Textbox1 with Button1 and Textbox2 with Button2


这篇关于如何在按钮单击时验证文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆