在ASP.Net 3.5中动态启用或禁用必需的字段验证程序 [英] Dynamically Enable or Disable Required Field Validator in ASP.Net 3.5

查看:78
本文介绍了在ASP.Net 3.5中动态启用或禁用必需的字段验证程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,





任何人都可以根据Dropdown的选择帮助我启用或禁用所需的字段验证器控件在asp.net 3.5中列表。我在asp.net 2.0中使用了相同的代码,并且工作正常。







问候,

P.Sri Pavan

解决方案





在客户端启用或禁用ASP.Net验证

rfv其他:是必填字段验证器

收起



  //  语法: 
ValidatorEnable(ValidatorContronName, Boolean );
// 说明:ValidatorContronName - 这是验证控件的ClientID。
布尔 - true (启用)/ false (禁用)
// 示例:
ValidatorEnable(document.getElementById(< span class =code-string>' <%= rfvOther.ClientID%>'), false );





您可以根据逻辑实现此功能。





如果您有任何疑问,请告诉我。



请提供投票:thumbsup:如果这会有所帮助,并且接受答案如果这是正确的答案。:ros:



谢谢,

Imdadhusen


你可以很容易地解除e服务器端的验证器



按照示例:



 <   asp:DropDownList     ID   =  DDL1    runat   = 服务器    AutoPostBack   =  true >  
< asp:ListItem < span class =code-keyword> = 1 & gt; 一个< / asp:ListItem >
< asp:ListItem = 2 > 两个< / asp :ListItem >
< asp:ListItem = 3 > 三个< / asp:ListItem >
< / asp:DropDownList >
< asp:TextBox ID = txt runat = 服务器 > < / asp:TextBox >
< < span class =code-leadattribute> asp:RequiredFieldValidator ID = Validator1 runat = 服务器 ControlToValidate = txt

ErrorMessage = 错误 > < / asp:RequiredFieldValidator >
< asp:按钮 runat = server 文字 = 保存 / >







并将此部分放入您的服务器端页面类:



  public   partial   class  WebForm1:System.Web.UI.Page 
{
pro tected void Page_Load( object sender,EventArgs e)
{
Validator1.Enabled =请求[DDL1.UniqueID] == 2 false true ;
}
}





当您在下拉列表中选择两个时,它将禁用验证器


您好,查看此链接





http://www.dotnetpools.com/2012/11/dynamically-enable-or-disable-validator.html [< a href =http://www.dotnetpools.com/2012/11/dynamically-enable-or-disable-validator.htmltarget =_ blanktitle =New Window> ^ ]

Dear Friends,


Can any one help me how to enable or disable the required field validator control based on selection of Dropdown list in asp.net 3.5.I have worked with the same peice of code in asp.net 2.0 and there it is working fine.



Regards,
P.Sri Pavan

解决方案

Hi,

Enable or Disable ASP.Net Validation on client side
rfvOther: is a Required Field Validator
Collapse

//Syntax:
ValidatorEnable(ValidatorContronName,Boolean);
//Explanation:ValidatorContronName - This is ClientID of the Validation control.
Boolean - true(Enable) / false(Disable)
//Example:
ValidatorEnable(document.getElementById('<%=rfvOther.ClientID%>'), false);



You can implement this function according you logic.


Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen


You can easily disable the validator on the server side

Follow the example:

<asp:DropDownList ID="DDL1" runat="server" AutoPostBack="true">
            <asp:ListItem Value="1">One</asp:ListItem>
            <asp:ListItem Value="2">Two</asp:ListItem>
            <asp:ListItem Value="3">Three</asp:ListItem>
        </asp:DropDownList>
        <asp:TextBox ID="txt" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="Validator1" runat="server" ControlToValidate="txt"

            ErrorMessage="error"></asp:RequiredFieldValidator>
        <asp:Button runat="server" Text="Save" />




and this piece place into your server side page class:

public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Validator1.Enabled = Request[DDL1.UniqueID] == "2" ? false : true;
    }
}



When you select "Two" in your dropdown, it will disable the validator


hi check this link


http://www.dotnetpools.com/2012/11/dynamically-enable-or-disable-validator.html[^]


这篇关于在ASP.Net 3.5中动态启用或禁用必需的字段验证程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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