Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
AshishChaudha 18-Oct-12 4:55am    
What actually you want?? An alert message after requirefieldValidator validation..
[no name] 18-Oct-12 4:55am    
yes

Try this
C#
if(!Page_ClientValidate())
{
   if( string.IsNullOrEmpty(document.getElementById("TextBox1").value) )
   {
      alert("Here I am");
      return false;
   }
}


Updated solution as suggested by Marcus.
Thanks
 
Share this answer
 
v3
Comments
fjdiewornncalwe 18-Oct-12 12:17pm    
+5. Just one note, the better way is to use string.IsNullorEmpty instead of == ""
AshishChaudha 18-Oct-12 23:55pm    
Thanks Marcus..I will update my self..
AshishChaudha 20-Oct-12 0:30am    
thanks for updating solution
If you need to show just alert on your textbox null value , you can simply use this javascript

C#
function validate() {
        if ((document.getElementById("TextBox1").value)=="")
        {
        alert("textbox shouldnot be empty");
        }
 
Share this answer
 
XML
<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>
 
Share this answer
 
Comments
[no name] 18-Oct-12 4:56am    
i am not want validation summary but want a alert message to user on screen.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900