如何在asp.net中验证文本框

问题描述:

嗨.
这是洛克什
我的问题是我有2个带有2个按钮的文本框,但textbox1应该在同一页面中对button1进行验证,而textbox2应该对在同一页面中的button2进行验证

帮助我

hi.
this is lokesh
my problem is i have 2 textboxes with 2 buttons but textbox1 should validate to button1 and textbox2 should validate to button2 in same page please

help me

设置Textbox1 Button1
validationgroup=a属性 并对Textbox2 Button2做相同的设置validationgroup=b.


记住 !!两个按钮的CausesValidation 必须为true.(Button1 Button2)


如果您有答案,请解决.


谢谢
Ashish
set validationgroup=a property of Textbox1 and Button1
and do the same set validationgroup=b for Textbox2 and Button2.


Remember !! CausesValidation must be true for both buttons.(Button1 and Button2)


Make it solution if you got your answer.


Thanks
Ashish


从MSDN中阅读以下文章,并使用validationGroup属性


http://msdn.microsoft.com/en-us/library/ms227424.aspx [ ^ ]
Read below article from MSDN and use validationGroup property


http://msdn.microsoft.com/en-us/library/ms227424.aspx[^]


我认为这会对您有所帮助,

i think this will help you,

<asp:textbox id="TextBox1" runat="server"></asp:textbox>
        <asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" errormessage="1st one" validationgroup="1st" controltovalidate="TextBox1">
        </asp:requiredfieldvalidator>
        <asp:button id="Button1" runat="server" text="Button" validationgroup="1st" causesvalidation="true" /><br />

        <asp:textbox id="TextBox2" runat="server"></asp:textbox>
        <asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" errormessage="2nd one" validationgroup="2nd" controltovalidate="TextBox2">
        </asp:requiredfieldvalidator>
        <asp:button id="Button2" runat="server" text="Button" validationgroup="2nd" causesvalidation="true" />