locked
regarding validation of controls: RRS feed

  • Question

  • Hi

    guys

    in the above code. my validation is not working. kindly help me.here is the code.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index3.aspx.cs" Inherits="NewFolder1_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    	<meta name="description" content="Your description goes here" />
    	<meta name="keywords" content="your,keywords,goes,here" />
    	<meta name="author" content="Your Name" />
    	<link rel="stylesheet" type="text/css" href="the-grid.css" title="The Grid" media="all" />
    	<title>Palle Technologies</title>
        <script language="javascript" type="text/javascript">
            function display1() {
    
                var res = document.getElementById("txtFirstname");
                var res1 = document.getElementById("TextBox1");
                var res2 = document.getElementById("txt_telephone");
                return res;
                return res1;
                return res2;
            }     
                              
        
        
        </script>
    </head>
    
    <body>
    <div id="width960">
    
    	<div id="header" class="row">
    		<div class="col c12">
    			<h1>Palle Technologies</h1>
    			<p class="slogan">We assure your success</p>
    			<p><a href="index.aspx"><img src="palle.jpg" alt="Palle Technologies" /></a></p>
    		</div>
    	</div>
    	
    	<div class="row">
    		<div id="sidebar" class="col c3">
    			<ul class="menu">
    				<li><a href="index.aspx">Home</a><br /></li>
    				<li><a href="index2.aspx">Careers</a><br /></li>
    				<li><a href="index3.aspx">Contact us</a><br /></li>
    				<li><a href="index4.aspx">About Us</a><br /></li>
    			</ul>
    		</div>
    	
    		<div id="content" class="col c9">
    
    			<div class="row">
    				<div class="col c9">
    					<h2>Welcome to Palle Technologies</h2>
    									</div>
    			</div>
    
    			<div class="row">
    				<div class="col c3">
    					<h3>Address</h3>
    					<p>No 15/6 (old no 112/2),
    Manish Complex (Above SBI, Opp.. Blossoms Hospital),
    Mangammana Palya Main Road,
    Bommanahalli,
    Bangalore - 560068</p>
    				</div>
    				<div class="col c3">
    					<h3>Telephone and Fax:</h3>
    					<p>Tel: 080-4164-5630 (OR) 080-6579-1087
    Fax: 080-41645630.</p>
    				</div>
    				<div class="col c3">
    					<h3>Enquiry Form:</h3>
                        <form runat="server">
                        <table>
                        
        <tr>
            <td>FirstName:</td>
            <td><asp:TextBox ID="txtFirstname" runat="server"></asp:TextBox></td>
            <td><asp:RegularExpressionValidator ID="revFirstName" runat="server" 
                    ControlToValidate="txtFirstname" ValidationExpression="[a-zA-Z]" 
                    ErrorMessage="Number not allowed" Display="Dynamic">
                </asp:RegularExpressionValidator>
             </td>
          </tr>
                          
        <tr>
            <td>LastName:</td>
            <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
            <td><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                    ControlToValidate="TextBox1" ValidationExpression="[a-zA-Z]" 
                    ErrorMessage="Number not allowed" Display="Dynamic">
                </asp:RegularExpressionValidator>
             </td>
          </tr>
    
          <tr>
            <td>Telephone:</td>
            <td><asp:TextBox ID="txt_telephone" runat="server" ></asp:TextBox></td>
            <td><asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" Font-Size="10px" ControlToValidate="txt_telephone" Display="Dynamic" ErrorMessage="<br>Telephone Number must be 7-11 digit" ValidationExpression="^[0-9]{7,11}$"></asp:RegularExpressionValidator>
             </td>
          </tr>
          <tr>
          <td>
          <asp:Button ID="btn" Text="submit" runat="server"   OnClientClick="display1()"/>
          </td>
          
          </tr>
    </table>
    </form>
    	
    				</div>
    			</div>
    		</div>
    	</div>
    		
    	<div id="footer" class="row">
    		<div class="col c12">
    			<p>&copy; 2013 Palle Technologies<br />
    			<a href="http://techpalle.com/">Template design</a> by <a href="http://techpalle.com/">Rakesh</a><br />Best hosted at <a href="http://techpalle.com/" title="Svenska Domäner AB">techpalle.com</a></p>
    		</div>
    	</div>
    </div>
    </body>
    </html>
    


    thanks and regard love4csharp

    Tuesday, April 23, 2013 5:08 PM

Answers

All replies

  • if u ve any doubt then plz let me know.

    thanks and regard love4csharp

    Tuesday, April 23, 2013 5:13 PM
  • You should try posting this on the ASP.Net forums.  This forum is for C# specific functionality - ASP.Net questions will be better answered there.



    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, April 23, 2013 5:22 PM
  • hi reed

    i tried but not getting ans....


    thanks and regard love4csharp

    Tuesday, April 23, 2013 5:23 PM
  • Your validation function code is given below

    function display1() {

                if (document.getElementById("txtFirstname").value == "")

                {

                    alert('First name should not blank');return false;

                }

                if (document.getElementById("TextBox1").value == "")

                {

                    alert('Last name should not blank'); return false;

                }

                if (document.getElementById("txt_telephone").value == "")

                {

                    alert('Telephone should not blank'); return false;

                }

                return true;

            }


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.

    Tuesday, April 23, 2013 5:31 PM
  • Hi

    Sankarsan Parida

    please see above code. i have used valditation ctrls in textboxes but they r not responding. Do u ve any idea what is the problem.??


    thanks and regard love4csharp

    Tuesday, April 23, 2013 5:37 PM
  • Just remove asp:RegularExpressionValidator .

    It will work


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.

    Tuesday, April 23, 2013 5:45 PM
  • hi

    sankarsan

    it is working but when i left the all threebox blank...it showing only one alert....at a time. So see code once again. what is the problem.


    thanks and regard love4csharp

    Tuesday, April 23, 2013 5:53 PM
  • If you want more than one alert just remove return false;

    But this is the solution where we will provide one by one message to a user.


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.

    Wednesday, April 24, 2013 1:05 AM