asp.net验证问题 [英] asp.net validation problem

查看:67
本文介绍了asp.net验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的asp.net网页中使用必填字段验证器,用于文本框和任何其他控件,

,点击提交按钮后,它们都可以正常工作,





但我的问题是当我在同一页面的任何其他地方使用按钮或链接按钮时

当我点击它们时:所有必需的字段验证器也出现,我无法点击该按钮而不填写所有文本框,



所以plz为我提供解决方案,验证是针对perticulor的按钮点击:





我的代码是:

i use required field validator in my asp.net web page for text box and any other controls,
and after click on submit button they all are work fine,


but my problem is when i use button or linkbutton, on any other place at the same page
and when i click them : all required field validator also appear and i am not able to click on that button without fill all text box,

so plz provide me solution ,that validation are fix for perticulor button click:


my code is:




<asp:TextBox ID="TxtUserID" Height="15px" placeholder="mail Id"  Width="180px"  CssClass="txtFinal" runat="server"

       ></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtUserID" ForeColor="Red" Font-Bold="true" ErrorMessage="**"></asp:RequiredFieldValidator>

     <asp:Button ID="BtnForSubmit" runat="server" Width="80px" Text="Submit"

         />













<asp:LinkButton ID="LinkButton2" PostBackUrl="http//:google.com" runat="server">Go Url</asp:LinkButton>









对于链接按钮单击我不想要验证出现在屏幕上,因为我只想要按钮点击验证:





For Link button Click i am not want that validation is appear in the screen because i want validation only for button click:

推荐答案

使用 ValidationGoup property。

例如:-

Use ValidationGoup property.
Eg.:-
<asp:textbox id="txt" runat="server"></asp:textbox>
 <asp:requiredfieldvalidator id="rfv" runat="server" errormessage="Enter Name."

                             Display="Dynamic" SetFocusOnError="true" 

                             ForeColor="Red"  

                             ValidationGroup="Group"

                             ControlToValidate="txt">
 </asp:requiredfieldvalidator>



使用相同的 ValidationGoup 用于您要执行验证的按钮。


Use same ValidationGoup for your button on which you want to perform validation.

 <asp:button id="btnNext" runat="server" text="Next"

             ValidationGroup="Group" />

</asp:button>





或者您可以将链接按钮的 CausesValidation 属性设置为false。



祝你好运。



Or you can set CausesValidation property of your link button to false.

Good luck.


这篇关于asp.net验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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