Results 1 to 5 of 5

Thread: {urgent} login and passwords

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    4

    validation in asp.net

    hello sir
    i am studing M.Tech, i developed database oriented(college orgainzation in intranet) project in asp.net. In that for example one student module is there in that it contain their personal details, i check the validation( only number is supported and only name is supported like that) but it will display the error messge to all control even i didn't check.
    so pls help me sir how to check the controls validations in asp.net

  2. #2

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    4

    validation in asp.net

    give some coding and idea what to check on text box support only number and another textbox support only char. in asp.net if both the condition are ok then only it move to another form

  3. #3
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: validation in asp.net

    Code:
    <script language="JavaScript">
    
    document.all["buttonName"].onclick = new function("Page_ValidationActive=true;");
    
    </script> 
     
    
    
    Page.Validate()
    
    If Page.IsValid Then
    	Lblerror.text = "your custom error message"
    	If Validationsummary1.Visible = True Then
    		Validationsummary1.Visible = False
    	End If
    Else
    	If Validationsummary1.Visible = False Then
    		Validationsummary1.Visible = True
    		lblError.Text = ""
    	End If
    End If
    Last edited by Hack; Mar 6th, 2006 at 11:38 AM. Reason: Added [code] [/code] tags for more clarity.

  4. #4
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: validation in asp.net

    CompareValidator1.aspx font size: 1 2 3 4 5 6 7


    View Sample
    Code:
    <%@ Page clienttarget=downlevel %>
    
    <html>
    <head>
    <title>CompareValidator Example</title>
    <link rel="stylesheet" href="/aspxtreme/shared/netdemos.css">
    
    <script language="C#" runat="server">
    void ValidateBtnClick ( object src, EventArgs e ) {
       if ( Page.IsValid ) {
          lblMessage.Text = "Comparison is valid!";
       }
       else {
          lblMessage.Text = "Comparison is not valid!";
       }
    }
    
    void lstOperator_SelectedIndexChanged ( object src, EventArgs e ) {
       comp1.Operator= ( ValidationCompareOperator ) lstOperator.SelectedIndex;
       comp1.Validate ( );
    }
    </script>
    </head>
    
    <body>
    <!-- #include virtual="~/shared/top.inc -->
    
    <div class="header"><h3>CompareValidator Example</h3></div>
    
    <hr size=1 width=90%>
    
    <p>Type a value in each textbox, select a comparison operator, then click "Validate" to test. </p>
    
    <form runat="server">
    <div align="center">
    
    <table bgcolor="#eeeeee" cellpadding=10>
    <tr valign="top">
       <td><h5>String 1:</h5>
          <asp:textbox selected id="txtComp" runat="server"></asp:textbox>
          <br>
          <asp:requiredfieldvalidator 
             controltovalidate="txtComp"
             errormessage="Field cannot be blank" runat="server" />
       </td>
       <td><h5>Comparison Operator:</h5>
       <asp:listbox id="lstOperator" onSelectedIndexChanged="lstOperator_SelectedIndexChanged" runat="server">
          <asp:listitem selected value="Equal">Equal</asp:listitem>
          <asp:listitem value="NotEqual">NotEqual</asp:listitem>
          <asp:listitem value="GreaterThan">GreaterThan</asp:listitem>
          <asp:listitem value="GreaterThanEqual">GreaterThanEqual</asp:listitem>
          <asp:listitem value="LessThan">LessThan</asp:listitem>
          <asp:listitem value="LessThanEqual">LessThanEqual</asp:listitem>
       </asp:listbox></td>
       <td>
          <h5>String 2:</h5>
          <asp:textbox id="txtCompTo" runat="server"></asp:textbox>
          <br>
          <asp:requiredfieldvalidator 
             controltovalidate="txtCompTo"
             errormessage="Field cannot be blank" runat="server" />
       </td></tr>
    </table>
    
    <br>
    
    <asp:button runat="server" 
       text="Validate" onClick="ValidateBtnClick" />
    
    <br>
    
    <asp:comparevalidator id="comp1" 
       controltovalidate="txtComp" 
       controltocompare="txtCompTo" 
       type="String" runat="server" />
    
    <br>
    
    <asp:label id="lblMessage" runat="server" />
    
    </div>
    </form>
    
    <hr size=1 width=90%>
    
    <!-- #include virtual="~/shared/viewsrc.inc" -->
    
    </body>
    </html>
    Last edited by Hack; Mar 6th, 2006 at 11:39 AM. Reason: Added [code] [/code] tags for more clarity.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: validation in asp.net

    I have no idea which of you two I should respond to.

    You can use a regular expression validator, with the regex

    \d

    to check for numbers only.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width