| | |
Conditional validation
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 493
Reputation:
Solved Threads: 92
1
#2 Oct 22nd, 2009
Try this code.
.aspx code
C# code
.aspx code
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoPage32.aspx.cs" Inherits="DemoPage32" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> Quantity : <asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox><br /> Date : <asp:TextBox ID="txtDate" runat="server"></asp:TextBox> <asp:CustomValidator ID="cvValidateDate" runat="server" ErrorMessage="Date must be entered"></asp:CustomValidator><br /> <asp:Button ID="btnValidate" runat="server" Text="Validate" onclick="btnValidate_Click" /> </div> </form> </body> </html>
C# code
ASP.NET Syntax (Toggle Plain Text)
protected void btnValidate_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtQuantity.Text)) { int qty = int.Parse(txtQuantity.Text); if (qty > 0) { if (String.IsNullOrEmpty(txtDate.Text)) { cvValidateDate.ErrorMessage = "Date must be entered"; cvValidateDate.IsValid = false; } } } }
•
•
Join Date: Oct 2007
Posts: 13
Reputation:
Solved Threads: 0
0
#3 Oct 22nd, 2009
Thanks Ramesh S, this is great. Exactly what I was looking for.
Just in case anyone is interested , here is the same script in VB:
Just in case anyone is interested , here is the same script in VB:
ASP.NET Syntax (Toggle Plain Text)
Protected Sub btnValidate_Click(ByVal sender As Object, ByVal e As EventArgs) If Not [String].IsNullOrEmpty(txtQuantity.Text) Then Dim qty As Integer = Integer.Parse(txtQuantity.Text) If qty > 0 Then If [String].IsNullOrEmpty(txtDate.Text) Then cvValidateDate.ErrorMessage = "Date must be entered" cvValidateDate.IsValid = False End If End If End If End Sub
![]() |
Similar Threads
- JavaScript Validation on Textbox (ASP.NET)
- Validation of age? (PHP)
- W3C Validation (HTML and CSS)
- coldfusion form validation question (ColdFusion)
Other Threads in the ASP.NET Forum
- Previous Thread: ASP.Net deployment problem
- Next Thread: Example of Inserting and Retrieving data from xml file
Views: 1324 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for asp.net, validation
.aspx .net 2.0 2008 action ajax ajax-doc analytics anathor asp asp.net beginner box businesslogiclayer buttons c# chat control crystal crystalreport database decimal developer development documents download ecommerce email embed expose fail feedback flash folder form freelance gridview html iframe iis images india input javascript learn-asp.net localhost loops mac method mssql multiple mvc mysql object online oracle pdf php pocketpc presence procedure programming project purchase python question redirect refer refresh relationaldatabases reports select serial sorting sql sql-server string studio textbox trouble validate validation vb.net virtualdirectory vista visual visualbasic visualbasic.net visualstudio w3c web webarchitecture webform window windows7 wizard word xhtml xml xsl






