在文本框上显示“需要现场验证为真"的警报消息 [英] show alert message with Require FIeld Validation true on textbox

查看:70
本文介绍了在文本框上显示“需要现场验证为真"的警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当某些文本框上要求字段验证器为true时,我想显示警报消息.

显示如何使用Require FIeld Validator进行操作?


请帮我........


谢谢和问候...
Mitesh

Hello To all,

I want to show alert message when there require field validator true on certain textbox.

show how can i do this with the Require FIeld Validator ?


Pleas help me........


Thanks and Regards...
Mitesh

推荐答案

尝试一下
if(!Page_ClientValidate())
{
   if( string.IsNullOrEmpty(document.getElementById("TextBox1").value) )
   {
      alert("Here I am");
      return false;
   }
}



根据Marcus的建议更新了解决方案.
谢谢



Updated solution as suggested by Marcus.
Thanks


如果您只需要在文本框null值上显示警报,则可以使用此javascript

If you need to show just alert on your textbox null value , you can simply use this javascript

function validate() {
        if ((document.getElementById("TextBox1").value)=="")
        {
        alert("textbox shouldnot be empty");
        }


<form id="form1" runat="server">
   <asp:Label ID="lblNameRequired" runat="server" Text="*Name :"></asp:Label>
   <asp:TextBox ID="txtNameRequired" runat="server" ValidationGroup="Validation"></asp:TextBox>
   <asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="txtNameRequired"

       Display="None" ErrorMessage="Name is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator>
   <br />
   <asp:Label ID="lblGenderRequired" runat="server" Text="*Gender :"></asp:Label>
   <asp:DropDownList ID="ddlGenderRequired" runat="server" ValidationGroup="Validation">
       <asp:ListItem Selected="True" Value="-1">--Select--</asp:ListItem>
       <asp:ListItem Value="0">Male</asp:ListItem>
       <asp:ListItem Value="1">Female</asp:ListItem>
   </asp:DropDownList>
   <asp:CompareValidator ID="CompareValidatorGender" runat="server" ControlToValidate="ddlGenderRequired"

       Display="None" ErrorMessage="Gender is Required" Operator="NotEqual" ValidationGroup="Validation"

       ValueToCompare="-1"></asp:CompareValidator>
   <br />
   <asp:Label ID="lblValidation" runat="server" Text="Fields marked with * are required"></asp:Label>
   <br />
   <asp:Button ID="btnValidate" runat="server" Text="Validate Input" ValidationGroup="Validation" />
   <br />
   <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"

       ShowSummary="False" ValidationGroup="Validation" />
   </form>


这篇关于在文本框上显示“需要现场验证为真"的警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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